Fosdccf.blog.chinaunix.net
sdccf
全部博文(19283)
Linux酷软(214)
tmp(0)
PostgreSQL(93)
Solaris(383)
AIX(173)
SCOUNIX(575)
DB2(1005)
Shell(386)
C/C++(1187)
MySQL(1750)
Sybase(465)
Oracle(3695)
Informix(548)
HP-UX(0)
IBM AIX(2)
Sun Solaris(0)
BSD(1)
Linux(8597)
SCO UNIX(23)
2011年(1)
2009年(125)
2008年(19094)
2007年(63)
clifford
linky521
曾德标
fengzhan
leon_yu
mcuflowe
yt200902
guanyuji
GY123456
snow888
carlos94
丸喵喵
sean229
cxunix
可怜的猪
cqxc413
xzzgege
wb123456
分类:
2008-04-14 20:19:57
JDBC连接DB2、Oracle、MySQL、PostgreSQL,并取得当前时间得实用代码: package com.terac.util; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement; public class DBTest { public static void main(String[] args) { try { String user = "user"; String password = "password"; String driver = "COM.ibm.db2.jdbc.net.DB2Driver"; //"oracle.jdbc.driver.OracleDriver"; //"com.mysql.jdbc.Driver"; //"org.postgresql.Driver"; String url = "jdbc:db2://localhost/a"; //"jdbc:oracle:thin:@localhost:1521:a"; //"jdbc:mysql://localhost/a"; //"jdbc:postgresql://localhost:5740/a"; String sql = "SELECT current timestamp FROM sysibm.sysdummy1"; //"SELECT sysdate FROM dual"; //"SELECT now()"; //"SELECT current_timestamp"; Class.forName(driver).newInstance(); Connection c = DriverManager.getConnection(url, user, password); Statement stmt = c.createStatement(); ResultSet rs = stmt.executeQuery(sql); while (rs.next()) { System.out.println(rs.getString(1)); } } catch (Exception e) { e.printStackTrace(); } } }
JDBC连接DB2、Oracle、MySQL、PostgreSQL,并取得当前时间得实用代码:
package com.terac.util; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement; public class DBTest { public static void main(String[] args) { try { String user = "user"; String password = "password"; String driver = "COM.ibm.db2.jdbc.net.DB2Driver"; //"oracle.jdbc.driver.OracleDriver"; //"com.mysql.jdbc.Driver"; //"org.postgresql.Driver"; String url = "jdbc:db2://localhost/a"; //"jdbc:oracle:thin:@localhost:1521:a"; //"jdbc:mysql://localhost/a"; //"jdbc:postgresql://localhost:5740/a"; String sql = "SELECT current timestamp FROM sysibm.sysdummy1"; //"SELECT sysdate FROM dual"; //"SELECT now()"; //"SELECT current_timestamp"; Class.forName(driver).newInstance(); Connection c = DriverManager.getConnection(url, user, password); Statement stmt = c.createStatement(); ResultSet rs = stmt.executeQuery(sql); while (rs.next()) { System.out.println(rs.getString(1)); } } catch (Exception e) { e.printStackTrace(); } } }
上一篇:DB2中更新执行计划的几个常见的方法 (2)
下一篇:Oracle与DB2、MySQL取前10条记录的对比 (1)
登录 注册