oracle註冊驅動 和 獲得連線的兩種方式
阿新 • • 發佈:2019-01-31
Connection con =null;
try {
//Class.forName("oracle.jdbc.driver.OracleDriver");//註冊驅動第一種方式***************
Driver drv = new oracle.jdbc.driver.OracleDriver();//註冊驅動第二種方式 *******************88
DriverManager.registerDriver(drv);
//String url="jdbc:oracle:"+"thin:@localhost:1521:orcl";//獲得連線的第一種方式******************
//String user="lhy";
//String password="lhy";
//con=DriverManager.getConnection(url, user, password);
Properties pro = new Properties();//獲得連線的第二種方法*******************************
pro.setProperty("user","lhy"); //鍵是user,不是username
pro.setProperty("password","lhy");
con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl",pro);
try {
//Class.forName("oracle.jdbc.driver.OracleDriver");//註冊驅動第一種方式***************
Driver drv = new oracle.jdbc.driver.OracleDriver();//註冊驅動第二種方式 *******************88
DriverManager.registerDriver(drv);
//String url="jdbc:oracle:"+"thin:@localhost:1521:orcl";//獲得連線的第一種方式******************
//String user="lhy";
//String password="lhy";
//con=DriverManager.getConnection(url, user, password);
Properties pro = new Properties();//獲得連線的第二種方法*******************************
pro.setProperty("user","lhy"); //鍵是user,不是username
pro.setProperty("password","lhy");
con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl",pro);