一个jdbc连接oracle8的例子(本机的页可以)!!!!
发表于:2007-07-04来源:作者:点击数:
标签:
try{ //加载一个 Oracle 驱动 DriverManager.registerDriver(new oracle .jdbc.driver.OracleDriver()); //使用OCI8连接到 数据库 conn=DriverManager.getConnection(jdbc:oracle:oci8:@DatabaseName+,user,password); }catch( SQL Exception e){//捕捉SQL违
try {
//加载一个
Oracle驱动
DriverManager.registerDriver(new
oracle.jdbc.driver.OracleDriver());
//使用OCI8连接到
数据库 conn=DriverManager.getConnection("jdbc:oracle:oci8:@DatabaseName"+,"user","password");
}catch(
SQLException e) { //捕捉SQL违例
System.out.println("Ora8iConnect在连接oracle8数据库时捕获");
while (e!=null)
{ System.out.println("SQLState:"+e.getSQLState());
System.out.println("Message :"+e.getMessage());
System.out.println("Vendor :"+e.getErrorCode());
e=e.getNextException();
System.out.println(" ");
}
conn=null;
}
try {
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
//orcl为你的数据库的SID
String url="jdbc:oracle:thin:@localhost:1521:orcl";
Connection conn= DriverManager.getConnection(url,"user","password");
}catch(SQLException e) { //捕捉SQL违例
System.out.println("Ora8iConnect在连接oracle8数据库时捕获");
while (e!=null)
{ System.out.println("SQLState:"+e.getSQLState());
System.out.println("Message :"+e.getMessage());
System.out.println("Vendor :"+e.getErrorCode());
e=e.getNextException();
System.out.println(" ");
}
conn=null;
}
原文转自:http://www.ltesting.net