使用Oracle JDBC驱动
2007-12-23 12:35:29 来源:WEB开发网核心提示:/*java PRogramming with Oracle JDBCby Donald Bales ISBN: 059600088XPublisher: O'Reilly*/import java.sql.Connection;import java.sql.DriverManager;import java
/*
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;
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", "scott", "tiger");
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) {
}
}
}
}
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;
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", "scott", "tiger");
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) {
}
}
}
}
(出处:http://www.cncms.com)
- ››oracle 恢复误删除的表和误更新的表
- ››Oracle分页查询排序数据重复问题
- ››Oracle创建dblink报错:ORA-01017、ORA-02063解决
- ››Oracle 提高SQL执行效率的方法
- ››Oracle 动态查询,EXECUTE IMMEDIATE select into...
- ››Oracle 11g必须开启的服务及服务详细介绍
- ››oracle性能34条优化技巧
- ››oracle数据库生成随机数的函数
- ››Oracle 数据库表空间容量调整脚本
- ››oracle单库彻底删除干净的方法
- ››使用word强大的搜索和替换功能
- ››Oracle创建表空间、创建用户以及授权、查看权限
更多精彩
赞助商链接