JDBC的使用
我在JBuilder下做一个应用,客户端可以通过IE查询服务器端的数据。客户端的查询是通过JDBC完成的,我在JBuilder
中的JDBC Explore配置了数据源,并连接数据库(Oracle 8.05)成功,但我在调试时系统总说数据库联不上(抛出异常SQLException)。
那位大虾能指点一下,不胜感激。
以下是部分程序:
driver = "oracle.jdbc.driver.OracleDriver";
u=userField.getText();
p=new String(passField.getPassword());
dbconnect=new CreatDbConnect(connectstring,u,p,driver,"srvdb");
public class CreatDbConnect {
Connection theConnection;
Statement theStatement;
boolean isconnect=false;
public CreatDbConnect(){
}
public CreatDbConnect(String url,String u,String p, String driverName,String type) {
try {
Class.forName(driverName);
theConnection = DriverManager.getConnection(url,u,p);
theStatement = theConnection.createStatement();
isconnect=true;
}
catch (ClassNotFoundException ex) {
JOptionPane.showMessageDialog(null,type+"数据库驱动程序错.\n"+ex.getMessage(),"错误",JOptionPane.ERROR_MESSAGE);
isconnect=false;
}
catch (SQLException ex) { //连接时,异常在此处抛出
JOptionPane.showMessageDialog(null,"不能连接到"+type+"数据库.\n"+ex.getMessage(),"错误",JOptionPane.ERROR_MESSAGE);
isconnect=false;
}
}
public Statement getStatement() {
return theStatement;
}
public void close() throws SQLException {
theStatement.close();
theConnection.close();
}
protected void finalize() throws Throwable {
close();
super.finalize();
}
}