import java.sql.*;
public class game1229{
public static void main (String args[]) {
Connection db = null; // DB接続オブジェクト
Statement st = null; // SQL文オブジェクト
ResultSet rs = null; // 問合せ結果オブジェクト
String url = "jdbc:odbc:SampleDB030"; // URL
String usr = ""; // ユーザ名
String pwd = ""; // パスワード
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("Connecting to " + url);
db = DriverManager.getConnection(url, usr, pwd);
st = db.createStatement();
st.executeUpdate("create table hellotbl (item varchar(16))");
st.executeUpdate("insert into hellotbl values ('Hello world!')");
st.executeUpdate("insert into hellotbl values ('ようこそ!')");
rs = st.executeQuery("select * from hellotbl");
if (rs != null) {
while (rs.next()) {
String item = rs.getString("item");
System.out.println(item);
}
}
rs.close();
st.executeUpdate("drop table hellotbl");
st.close();
db.close();
} catch (Exception ex) {ex.printStackTrace();}
}
}
最終更新:2011年03月21日 18:34