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);
时间: 2024-10-23 17:51:00