import java.sql.*;class dbConnect{ public static void main (String args[]) { try {
DriverManager.registerDriver(
new oracle.jdbc.driver.OracleDriver());
}
catch(SQLException e) {
System.out.println(
"Oops! Got a SQL error: " + e.getMessage());
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 * from phoneBook;");
while(rset.next())
{
for( int i=1; i<=16; i++)
{
System.out.print(rset.getString(i)+"/t");
}
System.out.print("/n");
} 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) {}
}
}
}
DriverManager.registerDriver(
new oracle.jdbc.driver.OracleDriver());
}
catch(SQLException e) {
System.out.println(
"Oops! Got a SQL error: " + e.getMessage());
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 * from phoneBook;");
while(rset.next())
{
for( int i=1; i<=16; i++)
{
System.out.print(rset.getString(i)+"/t");
}
System.out.print("/n");
} 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) {}
}
}
}
解决方案 »
- 请问为什么struts2要提供ServletActionContext和ActionContext两种方式访问Servlet API?
- 跪求, JOTM+Hibernate+MySQL详细配置过程。
- 请教一个JAVA服务器思路
- webwork和struts都是框架 有什么区别
- 学j2ee可以做什么工作
- hibernate 怎么根据检索单个对象
- jsp 中用js 变量的问题,来看看哇
- tomcat怎样设置网站的新目录呢
- 听说JBUIDER8比7快好多,是这样吗?如果真是,我也想装一个JBUIDER8但是不知道8好不好使?
- Lucene4.0+索引的效率问题
- client能调用local接口吗?
- 在线等待一个JMS发送和接收的例子!
2、Driver ClassName——oracle.jdbc.driver.OracleDriver
3、Properties——user=security
4、Password——security
For more information, see http://otn.oracle.com/docs/products/oracle9i/doc_library/release2/java.920/a96654/toc.htm <connection-url>jdbc:oracle:oci:@youroracle-tns-name</connection-url>
or
<connection-url>jdbc:oracle:oci:@(description=(address=(host=youroraclehost)(protocol=tcp)(port=1521))(connect_data=(SERVICE_NAME=yourservicename)))</connection-url> Clearly, its better to have TNS set up properly.