使用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)
[]
- ››使用脚本恢复WinXP系统的用户登录密码
- ››使用phpMyadmin创建数据库及独立数据库帐号
- ››使用Zend Framework框架中的Zend_Mail模块发送邮件...
- ››使用cout标准输出如何控制小数点后位数
- ››使用nofollow标签做SEO的技巧
- ››Oracle 数据库导入导出 dmp文件
- ››使用 WebSphere Message Broker 的 WebSphere Tra...
- ››使用SQL Server事件探查器做应用程序的性能分析
- ››使用SQL Server事件探查器分析死锁原因
- ››Oracle Application Server 的安装
- ››使用纯文本文件打造WCF服务
- ››使用 Dojo 开发定制 Business Space 小部件,第 4...
赞助商链接