java图书信息管理系统用文件存储数据

2022-08-08 科技 56阅读
倒数据库连接类jar包以SQL Server 2005 为例:

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class ConnectionUtil {
private static String DRIVER = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
private static String URL = "jdbc:sqlserver://127.0.0.1:1433;databaseName=数据库名";// 127.0.0.1
private static String USERNAME = "登录名";
private static String PASSWORD = "登录密码";

private static Connection CON = null;

public static Connection openConnection() {
try {
Class.forName(DRIVER);
CON = DriverManager.getConnection(URL, USERNAME, PASSWORD);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
return CON;
}

public static void closeConnection() {
try {
CON.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
声明:你问我答网所有作品(图文、音视频)均由用户自行上传分享,仅供网友学习交流。若您的权利被侵害,请联系fangmu6661024@163.com