package com;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class Dbconnection {
final static String DB_DRIVER = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
final static String url = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=information";
final static String user = "sa";
final static String password = "renxihai";
Connection conn = null;
Dbconnection() {
try {
Class.forName(DB_DRIVER).newInstance();
System.out.println("数据库驱动程序注册成功!");
conn = DriverManager.getConnection(url, user, password);
if (conn != null)
System.out.println("数据库连接成功");
} catch (Exception e) {
e.printStackTrace();
System.out.println("数据库连接失败");
}
}
Connection getconn() {
return conn;
}
void cutConnection(Connection dbconn){
if (dbconn != null) {
try {
dbconn.close();
System.out.println("数据库已经关闭");
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}