日期:2014-05-16 浏览次数:20365 次
public static void main(String[] args) throws ClassNotFoundException, SQLException { String driverName = "oracle.jdbc.driver.OracleDriver"; String userName = "xiaoqingp"; String password = "test"; Class.forName(driverName); Connection conn = DriverManager.getConnection( "jdbc:oracle:thin:@127.0.0.1:1521:XE", userName, password); Statement stm = conn.createStatement(); ResultSet rs = stm.executeQuery("select name from p_user"); while (rs.next()) { System.out.println(rs.getString("name")); } stm.close(); conn.close(); }
package org.xiaoqingp.test.dao; public class TestStatic { private static int count; static { count = 100; System.out.println("执行了static块=" + count); } public int getCount() { return count; } } public class TestClassForName { public static void main(String[] args) throws ClassNotFoundException { Class.forName("org.xiaoqingp.test.dao.TestStatic"); } }
Timestamp timestamp = Timestamp.valueOf("2000-01-01 00:00:00.0"); try { if (m_defaultDriver == null) { m_defaultDriver = new OracleDriver(); DriverManager.registerDriver(m_defaultDriver); } } catch (RuntimeException _ex) { } catch (SQLException _ex) { }
public static void main(String[] args) throws ClassNotFoundException, SQLException { String driverName = "oracle.jdbc.driver.OracleDriver"; String userName = "xiaoqingp"; String password = "test"; //Class.forName(driverName); DriverManager.registerDriver(new OracleDriver()); Connection conn = DriverManager.getConnection( "jdbc:oracle:thin:@127.0.0.1:1521:XE", userName, password); Statement stm = conn.createStatement(); ResultSet rs = stm.executeQuery("select name from p_user"); while (rs.next()) { System.out.println(rs.getString("name")); } stm.close(); conn.close(); }
for (int i = 0; i < drivers.size(); i++) { DriverInfo di = (DriverInfo) drivers.elementAt(i); // If the caller does not have permission to load the driver then // skip it. if (getCallerClass(callerCL, di.driverClassName) != di.driverClass) { println(" skipping: " + di); continue; } try { println(" trying " + di); Connection result = di.driver.connect(url, info); if (result != null) { // Success! println("getConnection returning " + di); return (result); } } catch (SQLException ex) { if (reason == null) { reason = ex; } } }