2015年9月10日 星期四

Java : 連結DB2資料庫(connect to DB2 database)

public class connectDb2{

public static void main(String[] args) throws Exception
{

DB_URL = "jdbc:db2://10.10.10.18/XXX";
Class.forName("com.ibm.db2.jcc.DB2Driver");
conn = DriverManager.getConnection(DB_URL, "USER", "PW");

//select
      PreparedStatement preStmt = conn.prepareStatement("Select * from DB2DATA");
ResultSet rs = preStmt.executeQuery();

if(rs.next())
{
String no = rs.getString("NO").toString();
}

//insert
PreparedStatement  preStmt = conn.prepareStatement("insert into DB2DATA");
preStmt.execute();

}

}

沒有留言:

張貼留言