简单的硬盘配置界面

源代码在线查看: dbconnection.java~14~

软件大小: 199 K
上传用户: ljw128
关键词: 硬盘
下载地址: 免注册下载 普通下载 VIP

相关代码

				package informationsystem.database;
				
				import java.sql.*;
				
				/**
				 * 这个类主要是维护与数据库的连接;
				 */
				public class DBConnection {
				  private String db_user;
				  private String db_password;
				
				  static final String DBDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
				
				  static final String strConn =
				      "jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=E:/information.mdb";
				
				  public DBConnection(String user, String password) {
				    this.db_user = user;
				    this.db_password = password;
				  }
				
				  // 获取数据库连接;
				  public Connection getConnection() throws SQLException {
				    DBConnection.loadDriver();
				
				    return java.sql.DriverManager.getConnection(this.strConn, this.db_user,
				                                                this.db_password);
				  }
				
				  /**
				   * 加载 JDBC-ODBC驱动
				   * @return String
				   */
				  private static String loadDriver() {
				    String sErr = "";
				    try {
				      java.sql.DriverManager.registerDriver( (java.sql.Driver) (Class
				          .forName(DBDriver).newInstance()));
				    }
				    catch (Exception e) {
				      sErr = e.toString();
				    }
				    return (sErr);
				  }
				
				  // 关闭数据库连接
				  public static void close(Connection conn) {
				    try {
				      conn.close();
				    }
				    catch (Exception ex) {
				      ex.printStackTrace();
				    }
				  }
				}
							

相关资源