package bactryki.dbconn;
import java.sql.*;
public class DBConn
{
private String driverClass;
private String urlpath;
private String myurl;
private String username;
private String password;
public String getDriverClass() {
return driverClass;
}
public void setDriverClass(String driverClass) {
this.driverClass = driverClass;
}
public String getUrlpath() {
return urlpath;
}
public void setUrlpath(String urlpath) {
this.urlpath = urlpath;
}
public String getMyurl() {
return myurl;
}
public void setMyurl(String myurl) {
this.myurl = myurl;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public DBConn()
{
try{
setDriverClass("com.microsoft.sqlserver.jdbc.SQLServerDriver");
setUrlpath("jdbc:sqlserver://localhost:1433;DatabaseName=");
setUsername("sa");
setPassword("123456");
}catch(Exception e)
{
System.out.print("加载数据库驱动程序时出现异常:");
e.printStackTrace();
}
}
public Connection dbconn(String dbname) throws ClassNotFoundException, SQLException
{
Connection conn = null;
setMyurl(urlpath+dbname);
Class.forName(driverClass);
conn=DriverManager.getConnection(myurl, username, password);
System.out.println("在DBConn中,数据库连接对象创建成功!");
return conn;
}
}