版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_22708467/article/details/83309893
public class selectPerson {
private Connection conn;
public selectPerson(String dburl,String dbuser,String dbpassword){
this.conn = getConnection(dburl,dbuser,dbpassword);
}
private Connection getConnection(String dburl,String dbuser,String dbpassword){
Connection connection = null;
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
connection = DriverManager.getConnection(dburl, dbuser, dbpassword);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
System.out.println("无效链接!!");
e.printStackTrace();
}
return connection;
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void main(String[] args){
String dburl = "jdbc:oracle:thin:@218.11.11.11:1521:orcl";
String dbuser = "name";
String dbpassword = "pwname";
selectPerson s = new selectPerson(dburl,dbuser,dbpassword);
}
}