当前位置: 技术问答>java相关
下面这个程序编译不通,怎么回事?提示public Connection { 出错!
来源: 互联网 发布时间:2015-01-25
本文导语: 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(){