只是个JAVA 的小程序~是关于添加书本子类的程序
源代码在线查看: dbconnect.java
/*
* DbConnect.java
*
* Created on 2007年10月29日, 上午8:31
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package addressBook;
import java.sql.*;
public class DbConnect {
private String dbURL;
private String user;
private String password;
/** Creates a new instance of DbConnect */
public DbConnect() {
}
public static void main(String args[]){
try{
DbConnect driver=new DbConnect();
driver.setURL("jdbc:odbc:txl");
driver.setUser("");
driver.setPassword("");
Connection con=driver.getConnection();
System.out.println(con.getCatalog());
System.out.println("成功加载ACCESS数据库驱动程序");
con.close();
}catch(Exception e){
System.out.println("加载ACCESS数据库驱动程序失败!");
System.out.println(e.toString());
}
}
public Connection getConnection(){
try{
//装载数据库驱动
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
return DriverManager.getConnection(dbURL,user,password);
}catch(Exception e){
System.out.println(e.toString());
}
return null;
}
public void setURL(String dbURL){
this.dbURL=dbURL;//设置数据库标志
}
public void setUser(String user){
this.user=user;
}
public void setPassword(String password){
this.password=password;
}
}