使用Oracle JDBC驱动
使用Oracle JDBC驱动
作者:佚名 文章来源:不详 点击数:
您正在看的J2EEJ2ME教程是:使用Oracle JDBC驱动。/* Java Programming with Oracle JDBC by Donald Bales ISBN: 059600088X Publisher: O'Reilly */
import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement;
更新时间:2007-4-19
public class TestClassForNameApp {
public static void main(String args[]) { try {
Class.forName(\"oracle.jdbc.driver.OracleDriver\"); } catch (ClassNotFoundException e) { System.out
.println(\"Oops! Can't find class oracle.jdbc.driver.OracleDriver\"); System.exit(1); }
Connection conn = null; Statement stmt = null; ResultSet rset = null; try {
conn = DriverManager.getConnection(
\"jdbc:oracle:thin:@dssw2k01:1521:orcl\
stmt = conn.createStatement(); rset = stmt
.executeQuery(\"select 'Hello '||USER||'!' result from dual\"); while (rset.next())
System.out.println(rset.getString(1)); rset.close(); rset = null; stmt.close(); stmt = null; conn.close(); conn = null;
} catch (SQLException e) {
System.out.println(\"Darn! A SQL error: \" + e.getMessage()); } finally {
if (rset != null) try { rset.close();
} catch (SQLException ignore) { }
if (stmt != null) try { stmt.close();
} catch (SQLException ignore) { }
if (conn != null) try { conn.close();
} catch (SQLException ignore) { } } }
}
因篇幅问题不能全部显示,请点此查看更多更全内容