Hello, JDBC Type4(Jasmin) World!
Posted on 10月 30th, 2012 by cx20
JDBC Type4
JDBC(Java Database Connectivity)は、Java 用のデータベース接続 API である。実装方法によりType1~4の4つのタイプが存在する。
Type4 は DBMS のクライアントライブラリを使用しない Pure Java の DBMS ドライバである。
以下は Jasmin による JDBC ライブラリの使用例となっている。
ソースコード(Jasmin + JDBC Type4 + SQL Server)
; Produced by NeoJasminVisitor (tinapoc)
; http://tinapoc.sourceforge.net
; The original JasminVisitor is part of the BCEL
; http://jakarta.apache.org/bcel/
; Tue Oct 16 23:33:16 JST 2012
.bytecode 50.0
.source Hello.java
.class Hello
.super java/lang/Object
.method <init>()V
.limit stack 1
.limit locals 1
.var 0 is this LHello; from Label0 to Label1
Label0:
.line 3
0: aload_0
1: invokespecial java/lang/Object/<init>()V
Label1:
4: return
.end method
.method public static main([Ljava/lang/String;)V
.limit stack 3
.limit locals 4
.var 0 is arg0 [Ljava/lang/String; from Label2 to Label3
Label2:
.line 6
0: ldc "com.microsoft.sqlserver.jdbc.SQLServerDriver"
2: invokestatic java/lang/Class/forName(Ljava/lang/String;)Ljava/lang/Class;
5: pop
.line 8
6: ldc "jdbc:sqlserver://;serverName=localhost"
8: ldc "sa"
10: ldc "P@ssW0rd"
12: invokestatic java/sql/DriverManager/getConnection(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Ljava/sql/Connection;
15: astore_1
.line 9
16: aload_1
17: invokeinterface java/sql/Connection/createStatement()Ljava/sql/Statement; 1
22: astore_2
.line 10
23: aload_2
24: ldc "SELECT 'Hello, JDBC Type4 World!' AS Message"
26: invokeinterface java/sql/Statement/executeQuery(Ljava/lang/String;)Ljava/sql/ResultSet; 2
31: astore_3
Label1:
.line 11
32: aload_3
33: invokeinterface java/sql/ResultSet/next()Z 1
38: ifeq Label0
.line 12
41: getstatic java.lang.System.out Ljava/io/PrintStream;
44: aload_3
45: iconst_1
46: invokeinterface java/sql/ResultSet/getString(I)Ljava/lang/String; 2
51: invokevirtual java/io/PrintStream/println(Ljava/lang/String;)V
54: goto Label1
Label0:
.line 14
57: aload_3
58: invokeinterface java/sql/ResultSet/close()V 1
.line 15
63: aload_2
64: invokeinterface java/sql/Statement/close()V 1
.line 16
69: aload_1
70: invokeinterface java/sql/Connection/close()V 1
Label3:
.line 17
75: return
.throws java/lang/Exception
.end method |
; Produced by NeoJasminVisitor (tinapoc)
; http://tinapoc.sourceforge.net
; The original JasminVisitor is part of the BCEL
; http://jakarta.apache.org/bcel/
; Tue Oct 16 23:33:16 JST 2012
.bytecode 50.0
.source Hello.java
.class Hello
.super java/lang/Object
.method <init>()V
.limit stack 1
.limit locals 1
.var 0 is this LHello; from Label0 to Label1
Label0:
.line 3
0: aload_0
1: invokespecial java/lang/Object/<init>()V
Label1:
4: return
.end method
.method public static main([Ljava/lang/String;)V
.limit stack 3
.limit locals 4
.var 0 is arg0 [Ljava/lang/String; from Label2 to Label3
Label2:
.line 6
0: ldc "com.microsoft.sqlserver.jdbc.SQLServerDriver"
2: invokestatic java/lang/Class/forName(Ljava/lang/String;)Ljava/lang/Class;
5: pop
.line 8
6: ldc "jdbc:sqlserver://;serverName=localhost"
8: ldc "sa"
10: ldc "P@ssW0rd"
12: invokestatic java/sql/DriverManager/getConnection(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Ljava/sql/Connection;
15: astore_1
.line 9
16: aload_1
17: invokeinterface java/sql/Connection/createStatement()Ljava/sql/Statement; 1
22: astore_2
.line 10
23: aload_2
24: ldc "SELECT 'Hello, JDBC Type4 World!' AS Message"
26: invokeinterface java/sql/Statement/executeQuery(Ljava/lang/String;)Ljava/sql/ResultSet; 2
31: astore_3
Label1:
.line 11
32: aload_3
33: invokeinterface java/sql/ResultSet/next()Z 1
38: ifeq Label0
.line 12
41: getstatic java.lang.System.out Ljava/io/PrintStream;
44: aload_3
45: iconst_1
46: invokeinterface java/sql/ResultSet/getString(I)Ljava/lang/String; 2
51: invokevirtual java/io/PrintStream/println(Ljava/lang/String;)V
54: goto Label1
Label0:
.line 14
57: aload_3
58: invokeinterface java/sql/ResultSet/close()V 1
.line 15
63: aload_2
64: invokeinterface java/sql/Statement/close()V 1
.line 16
69: aload_1
70: invokeinterface java/sql/Connection/close()V 1
Label3:
.line 17
75: return
.throws java/lang/Exception
.end method
実行方法(Jasmin + JDBC Type4 + SQL Server)
C:¥> java -jar jasmin.jar Hello.j
C:¥> java -cp sqljdbc4.jar;. Hello |
C:¥> java -jar jasmin.jar Hello.j
C:¥> java -cp sqljdbc4.jar;. Hello
ソースコード(Jasmin + JDBC Type4 + Oracle)
; Produced by NeoJasminVisitor (tinapoc)
; http://tinapoc.sourceforge.net
; The original JasminVisitor is part of the BCEL
; http://jakarta.apache.org/bcel/
; Tue Oct 16 23:37:45 JST 2012
.bytecode 50.0
.source Hello.java
.class Hello
.super java/lang/Object
.method <init>()V
.limit stack 1
.limit locals 1
.var 0 is this LHello; from Label0 to Label1
Label0:
.line 3
0: aload_0
1: invokespecial java/lang/Object/<init>()V
Label1:
4: return
.end method
.method public static main([Ljava/lang/String;)V
.limit stack 3
.limit locals 4
.var 0 is arg0 [Ljava/lang/String; from Label2 to Label3
Label2:
.line 6
0: ldc "oracle.jdbc.driver.OracleDriver"
2: invokestatic java/lang/Class/forName(Ljava/lang/String;)Ljava/lang/Class;
5: pop
.line 8
6: ldc "jdbc:oracle:thin:@localhost:1521:orcl"
8: ldc "scott"
10: ldc "tiger"
12: invokestatic java/sql/DriverManager/getConnection(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Ljava/sql/Connection;
15: astore_1
.line 9
16: aload_1
17: invokeinterface java/sql/Connection/createStatement()Ljava/sql/Statement; 1
22: astore_2
.line 10
23: aload_2
24: ldc "SELECT 'Hello, JDBC Type4 World!' AS Message FROM DUAL"
26: invokeinterface java/sql/Statement/executeQuery(Ljava/lang/String;)Ljava/sql/ResultSet; 2
31: astore_3
Label1:
.line 11
32: aload_3
33: invokeinterface java/sql/ResultSet/next()Z 1
38: ifeq Label0
.line 12
41: getstatic java.lang.System.out Ljava/io/PrintStream;
44: aload_3
45: iconst_1
46: invokeinterface java/sql/ResultSet/getString(I)Ljava/lang/String; 2
51: invokevirtual java/io/PrintStream/println(Ljava/lang/String;)V
54: goto Label1
Label0:
.line 14
57: aload_3
58: invokeinterface java/sql/ResultSet/close()V 1
.line 15
63: aload_2
64: invokeinterface java/sql/Statement/close()V 1
.line 16
69: aload_1
70: invokeinterface java/sql/Connection/close()V 1
Label3:
.line 17
75: return
.throws java/lang/Exception
.end method |
; Produced by NeoJasminVisitor (tinapoc)
; http://tinapoc.sourceforge.net
; The original JasminVisitor is part of the BCEL
; http://jakarta.apache.org/bcel/
; Tue Oct 16 23:37:45 JST 2012
.bytecode 50.0
.source Hello.java
.class Hello
.super java/lang/Object
.method <init>()V
.limit stack 1
.limit locals 1
.var 0 is this LHello; from Label0 to Label1
Label0:
.line 3
0: aload_0
1: invokespecial java/lang/Object/<init>()V
Label1:
4: return
.end method
.method public static main([Ljava/lang/String;)V
.limit stack 3
.limit locals 4
.var 0 is arg0 [Ljava/lang/String; from Label2 to Label3
Label2:
.line 6
0: ldc "oracle.jdbc.driver.OracleDriver"
2: invokestatic java/lang/Class/forName(Ljava/lang/String;)Ljava/lang/Class;
5: pop
.line 8
6: ldc "jdbc:oracle:thin:@localhost:1521:orcl"
8: ldc "scott"
10: ldc "tiger"
12: invokestatic java/sql/DriverManager/getConnection(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Ljava/sql/Connection;
15: astore_1
.line 9
16: aload_1
17: invokeinterface java/sql/Connection/createStatement()Ljava/sql/Statement; 1
22: astore_2
.line 10
23: aload_2
24: ldc "SELECT 'Hello, JDBC Type4 World!' AS Message FROM DUAL"
26: invokeinterface java/sql/Statement/executeQuery(Ljava/lang/String;)Ljava/sql/ResultSet; 2
31: astore_3
Label1:
.line 11
32: aload_3
33: invokeinterface java/sql/ResultSet/next()Z 1
38: ifeq Label0
.line 12
41: getstatic java.lang.System.out Ljava/io/PrintStream;
44: aload_3
45: iconst_1
46: invokeinterface java/sql/ResultSet/getString(I)Ljava/lang/String; 2
51: invokevirtual java/io/PrintStream/println(Ljava/lang/String;)V
54: goto Label1
Label0:
.line 14
57: aload_3
58: invokeinterface java/sql/ResultSet/close()V 1
.line 15
63: aload_2
64: invokeinterface java/sql/Statement/close()V 1
.line 16
69: aload_1
70: invokeinterface java/sql/Connection/close()V 1
Label3:
.line 17
75: return
.throws java/lang/Exception
.end method
実行方法(Jasmin + JDBC Type4 + Oracle)
C:¥> java -jar jasmin.jar Hello.j
C:¥> java -cp ojdbc6.jar;. Hello |
C:¥> java -jar jasmin.jar Hello.j
C:¥> java -cp ojdbc6.jar;. Hello
ソースコード(Jasmin + JDBC Type4 + MySQL)
; Produced by NeoJasminVisitor (tinapoc)
; http://tinapoc.sourceforge.net
; The original JasminVisitor is part of the BCEL
; http://jakarta.apache.org/bcel/
; Tue Oct 16 23:37:45 JST 2012
.bytecode 50.0
.source Hello.java
.class Hello
.super java/lang/Object
.method <init>()V
.limit stack 1
.limit locals 1
.var 0 is this LHello; from Label0 to Label1
Label0:
.line 3
0: aload_0
1: invokespecial java/lang/Object/<init>()V
Label1:
4: return
.end method
.method public static main([Ljava/lang/String;)V
.limit stack 3
.limit locals 4
.var 0 is arg0 [Ljava/lang/String; from Label2 to Label3
Label2:
.line 6
0: ldc "com.mysql.jdbc.Driver"
2: invokestatic java/lang/Class/forName(Ljava/lang/String;)Ljava/lang/Class;
5: pop
.line 8
6: ldc "jdbc:mysql://localhost:3306"
8: ldc "root"
10: ldc "P@ssW0rd"
12: invokestatic java/sql/DriverManager/getConnection(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Ljava/sql/Connection;
15: astore_1
.line 9
16: aload_1
17: invokeinterface java/sql/Connection/createStatement()Ljava/sql/Statement; 1
22: astore_2
.line 10
23: aload_2
24: ldc "SELECT 'Hello, JDBC Type4 World!' AS Message"
26: invokeinterface java/sql/Statement/executeQuery(Ljava/lang/String;)Ljava/sql/ResultSet; 2
31: astore_3
Label1:
.line 11
32: aload_3
33: invokeinterface java/sql/ResultSet/next()Z 1
38: ifeq Label0
.line 12
41: getstatic java.lang.System.out Ljava/io/PrintStream;
44: aload_3
45: iconst_1
46: invokeinterface java/sql/ResultSet/getString(I)Ljava/lang/String; 2
51: invokevirtual java/io/PrintStream/println(Ljava/lang/String;)V
54: goto Label1
Label0:
.line 14
57: aload_3
58: invokeinterface java/sql/ResultSet/close()V 1
.line 15
63: aload_2
64: invokeinterface java/sql/Statement/close()V 1
.line 16
69: aload_1
70: invokeinterface java/sql/Connection/close()V 1
Label3:
.line 17
75: return
.throws java/lang/Exception
.end method |
; Produced by NeoJasminVisitor (tinapoc)
; http://tinapoc.sourceforge.net
; The original JasminVisitor is part of the BCEL
; http://jakarta.apache.org/bcel/
; Tue Oct 16 23:37:45 JST 2012
.bytecode 50.0
.source Hello.java
.class Hello
.super java/lang/Object
.method <init>()V
.limit stack 1
.limit locals 1
.var 0 is this LHello; from Label0 to Label1
Label0:
.line 3
0: aload_0
1: invokespecial java/lang/Object/<init>()V
Label1:
4: return
.end method
.method public static main([Ljava/lang/String;)V
.limit stack 3
.limit locals 4
.var 0 is arg0 [Ljava/lang/String; from Label2 to Label3
Label2:
.line 6
0: ldc "com.mysql.jdbc.Driver"
2: invokestatic java/lang/Class/forName(Ljava/lang/String;)Ljava/lang/Class;
5: pop
.line 8
6: ldc "jdbc:mysql://localhost:3306"
8: ldc "root"
10: ldc "P@ssW0rd"
12: invokestatic java/sql/DriverManager/getConnection(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Ljava/sql/Connection;
15: astore_1
.line 9
16: aload_1
17: invokeinterface java/sql/Connection/createStatement()Ljava/sql/Statement; 1
22: astore_2
.line 10
23: aload_2
24: ldc "SELECT 'Hello, JDBC Type4 World!' AS Message"
26: invokeinterface java/sql/Statement/executeQuery(Ljava/lang/String;)Ljava/sql/ResultSet; 2
31: astore_3
Label1:
.line 11
32: aload_3
33: invokeinterface java/sql/ResultSet/next()Z 1
38: ifeq Label0
.line 12
41: getstatic java.lang.System.out Ljava/io/PrintStream;
44: aload_3
45: iconst_1
46: invokeinterface java/sql/ResultSet/getString(I)Ljava/lang/String; 2
51: invokevirtual java/io/PrintStream/println(Ljava/lang/String;)V
54: goto Label1
Label0:
.line 14
57: aload_3
58: invokeinterface java/sql/ResultSet/close()V 1
.line 15
63: aload_2
64: invokeinterface java/sql/Statement/close()V 1
.line 16
69: aload_1
70: invokeinterface java/sql/Connection/close()V 1
Label3:
.line 17
75: return
.throws java/lang/Exception
.end method
実行方法(Jasmin + JDBC Type4 + MySQL)
C:¥> java -jar jasmin.jar Hello.j
C:¥> java -cp mysql-connector-java-5.1.22-bin.jar;. Hello |
C:¥> java -jar jasmin.jar Hello.j
C:¥> java -cp mysql-connector-java-5.1.22-bin.jar;. Hello
実行結果
Tags: JDBC, JDBC Type4
Categories: Jasmin, JDBC, JDBC Type4