java から mysql に接続してみた。TIMEの上限値が取得できない障害に出会ったが、24時間以内であれば問題はなかった。また、指数表記に差異が見られたが原因は
ここに記載されているデフォルトのフォーマットが異なるのだろう。bit 型の表記は、mysql コマンドで表示させた時と同じサイコロ状の表記となった。(
サイコロ状表記についてはこちら)
| タイプ |
DB設定値 |
Java取込値
|
| BIT(8) |
3 |
3
|
| TINYINT |
127 |
127
|
| BOOL |
1 |
1
|
| SMALLINT |
32767 |
32767
|
| MEDIUMINT |
8388607 |
8388607
|
| INT |
2147483647 |
2147483647
|
| BIGINT |
9223372036854775807 |
9223372036854775807
|
| FLOAT |
3.402823466E+38 |
3.40282e38
|
| DOUBLE |
1.7976931348623157E+308 |
1.7976931348623157e308
|
| DECIMAL |
1 |
1
|
| DATE |
'9999-12-31' |
9999-12-31
|
| DATETIME |
'9999-12-3123:59:59' |
9999-12-31 23:59:59.0
|
| TIMESTAMP |
'2037-12-3123:59:59' |
2037-12-31 23:59:59.0
|
| TIME |
'838:59:59' |
×
|
| YEAR |
2155 |
2155-01-01
|
| CHAR |
'a' |
a
|
| VARCHAR(255) |
'ab1' |
ab1
|
| BINARY(255),@ |
'ab2' |
ab2
|
| VARBINARY(255) |
'ab3' |
ab3
|
| TINYBLOB |
'ab4' |
ab4
|
| TINYTEXT |
'ab5' |
ab5
|
| BLOB(255) |
'ab6' |
ab6
|
| TEXT(255) |
'ab7' |
ab7
|
| MEDIUMBLOB |
'ab8' |
ab8
|
| MEDIUMTEXT |
'ab9' |
ab9
|
| LONGBLOB |
'abA' |
abA
|
| LONGTEXT |
'abB' |
abB
|
| ENUM('a','b','c'), |
'c' |
c
|
| SET('e','f','g') |
'ef' |
e,f
|
import java.sql.*;
import java.lang.Long;
public class test11 {
public static void main(String[] args) {
String msg = "";
try {
// ドライバロード
Class.forName("org.gjt.mm.mysql.Driver");
// MySQLに接続
Connection con = DriverManager.getConnection(
"jdbc:mysql://localhost/naoki", "user", "password");
// ステートメント生成
Statement stmt = con.createStatement();
// SQLを実行
String sqlStr = "SELECT * FROM test01";
ResultSet rs = stmt.executeQuery(sqlStr);
// 結果行をループ
while(rs.next()){
// レコードの値
System.out.println(rs.getString("col01"));
System.out.println(rs.getString("col02"));
System.out.println(rs.getString("col03"));
System.out.println(rs.getString("col04"));
System.out.println(rs.getString("col05"));
System.out.println(rs.getString("col06"));
System.out.println(rs.getString("col07"));
System.out.println(rs.getString("col08"));
System.out.println(rs.getString("col09"));
System.out.println(rs.getString("col10"));
System.out.println(rs.getString("col11"));
System.out.println(rs.getString("col12"));
System.out.println(rs.getString("col13"));
System.out.println(rs.getString("col14"));
System.out.println(rs.getString("col15"));
System.out.println(rs.getString("col16"));
System.out.println(rs.getString("col17"));
System.out.println(rs.getString("col18"));
System.out.println(rs.getString("col19"));
System.out.println(rs.getString("col20"));
System.out.println(rs.getString("col21"));
System.out.println(rs.getString("col22"));
System.out.println(rs.getString("col23"));
System.out.println(rs.getString("col24"));
System.out.println(rs.getString("col25"));
System.out.println(rs.getString("col26"));
System.out.println(rs.getString("col27"));
System.out.println(rs.getString("col28"));
System.out.println(rs.getString("col29"));
}
// 接続を閉じる
rs.close();
stmt.close();
con.close();
}
catch (ClassNotFoundException e){
msg = "ドライバのロードに失敗しました";
System.out.println(msg);
}
catch (SQLException e) {
msg = "SQLに失敗しました";
System.out.println(msg);
e.printStackTrace();
}
}
}
0 件のコメント:
コメントを投稿