将Oracle 安装路径I:/oracle/product/10.1.0/Db_1/jdbc/lib下的classes12.jar复制到Tomcat的安装目录I:/Program Files/Apache Software Foundation/Tomcat 6.0/lib 和 I:/Program Files/Apache Software Foundation/Tomcat 5.5/common/lib下;
java示例代码如下:
try
{
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
}
catch(java.lang.ClassNotFoundException e)
{
System.out.println("ClassNotFoundException:");
System.out.println(e);
}
catch (InstantiationException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (IllegalAccessException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
try
{
String url="jdbc:oracle:thin:@localhost:1521:orcl";
Connection con=DriverManager.getConnection(url,"system","oracle");
Statement stmt=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
stmt.executeUpdate("insert into test values(1,'aa')");
stmt.executeUpdate("insert into test values(2,'bb')");
ResultSet rs=stmt.executeQuery("select * from test");//
while(rs.next())
{
int id=rs.getInt("id");
String txt=rs.getString("txt");
out.println("id:"+id+",txt:"+txt+"<br/>");
}
rs.close(); //
stmt.close();
con.close();
}
catch(SQLException ex)
{
out.println("SQLException: " + ex.getMessage());
}