?? dbconnection.java
字號:
/*
* Created on 2006-1-19
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package cn.com.aheadsoft.conndb;
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.SQLException;
import java.io.Serializable;
/**
* @author Administrator
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class DBConnection implements Serializable{
private String db_url;
private String db_driver;
private String db_user;
private String db_password;
private Connection con = null;
/**
* Get a connection
* @return Connection
* @throws SQLException this method
*/
public Connection getConnection() throws SQLException {
//System.out.println(db_url);
con=DriverManager.getConnection(db_url,db_user,db_password);
return con;
}
public DBConnection() {
init();
}
private void init() {
Configuration cfg = Configuration.getInstance();
this.db_driver = cfg.getValue("DB.DRIVER");
this.db_url = cfg.getValue("DB.URL");
this.db_user = cfg.getValue("DB.USER");
this.db_password = cfg.getValue("DB.PASSWORD");
System.out.print(db_driver);
//this.db_driver ="sun.jdbc.odbc.JdbcOdbcDriver";
// this.db_url="jdbc:odbc:DRIVER={Microsoft Access Driver (*.mdb)};DBQ=D:\\jzw.mdb";
//this.db_user="root";
// this.db_password="aheadsoft";
try {
Class.forName(db_driver);
}catch (ClassNotFoundException ex) {
System.out.println(ex);
}
}
public void CloseCon()throws Exception{
if(con != null)
con.close();
}
public static void main(String[] args)throws SQLException{
DBConnection aa= new DBConnection();
if(aa.getConnection()!=null)
System.out.println("connect success");
else
System.out.println("connect fail");
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -