[java]代码库
package db;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
public class DBConnection {
public Connection getConnection() {
Connection conn = null;
try {
// 加载驱动
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
} catch (Exception e) {
e.printStackTrace();
System.out.println("class有问题");
}
try {
String url = "jdbc:sqlserver://localhost;DatabaseName=ETclothesSystem";
conn = DriverManager.getConnection(url, "sa", "123456");
System.out.println("连接成功");
} catch (Exception e) {
// TODO: handle exception
System.out.println("url有问题");
}
return conn;
}
public void close(Connection conn, Statement stmt, ResultSet rs) {
try {
if (rs != null)
rs.close();
if (stmt != null)
stmt.close();
if (conn != null)
conn.close();
} catch (Exception e) {
}
}
}
[源代码打包下载]