Oracle資料庫連線方式

fsz521job發表於2005-12-05
Oracle資料庫的OCI和thin連線方式;[@more@]

import java.sql.Connection;
import java.sql.DriverManager;

public class ConnDB
{
//private static String url = "jdbc:oracle:thin:@192.168.0.1:1521:DBName";
private static String url = "jdbc:oracle:oci:@TNSName";
private static String user = "username";
private static String password = "password";

public ConnDB()
{
}

public static Connection getConnection()
{
Connection conn;
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
conn= DriverManager.getConnection(url , user, password);
return conn;
}
catch(Exception e)
{
e.printStackTrace();
return null;
}
}
}

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/300209/viewspace-811249/,如需轉載,請註明出處,否則將追究法律責任。

相關文章