当前位置: 技术问答>java相关
有什么问题吗?不知道出了什么错,
来源: 互联网 发布时间:2015-01-26
本文导语: package SiteData; /** * Title: * Description: * Copyright: Copyright (c) 2001 * Company: * @author * @version 1.0 */ import java.sql.*; public class Connection { String DBDriver = "sun.jdbc.odbc.JdbcOdbcDriver"; String ConnStr = "jdbc:odb...
package SiteData;
/**
* Title:
* Description:
* Copyright: Copyright (c) 2001
* Company:
* @author
* @version 1.0
*/
import java.sql.*;
public class Connection {
String DBDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
String ConnStr = "jdbc:odbc:Customers";
Connection conn = null;
ResultSet rs = null;
public Connection {
try {
Class.forName(DBDriver);
//加载数据库驱动程序
}
catch(java.lang.ClassNotFoundException e) {
System.err.println("DBconn (): " + e.getMessage());
}
}
public ResultSet executeQuery(String sql) {
rs = null;
try {
conn = DriverManager.getConnection(ConnStr);
//与DBMS建立链接
Statement stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
}
catch(SQLException ex) {
System.err.println("aq.executeQuery:"+ex.getMessage());
}
return rs;
}
}
/**
* Title:
* Description:
* Copyright: Copyright (c) 2001
* Company:
* @author
* @version 1.0
*/
import java.sql.*;
public class Connection {
String DBDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
String ConnStr = "jdbc:odbc:Customers";
Connection conn = null;
ResultSet rs = null;
public Connection {
try {
Class.forName(DBDriver);
//加载数据库驱动程序
}
catch(java.lang.ClassNotFoundException e) {
System.err.println("DBconn (): " + e.getMessage());
}
}
public ResultSet executeQuery(String sql) {
rs = null;
try {
conn = DriverManager.getConnection(ConnStr);
//与DBMS建立链接
Statement stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
}
catch(SQLException ex) {
System.err.println("aq.executeQuery:"+ex.getMessage());
}
return rs;
}
}
|
應該是:
public Connection (){
try {
Class.forName(DBDriver);
//加载数据库驱动程序
}
catch(java.lang.ClassNotFoundException e) {
System.err.println("DBconn (): " + e.getMessage());
}
}
吧.
public Connection (){
try {
Class.forName(DBDriver);
//加载数据库驱动程序
}
catch(java.lang.ClassNotFoundException e) {
System.err.println("DBconn (): " + e.getMessage());
}
}
吧.
|
bobosji(波波司机)
^^
你事误导啊!
构造函数!
^^
你事误导啊!
构造函数!
|
public Connection() {