当前位置: 技术问答>java相关
请大家进来看一下,为什么错了,一个很简单的javabean,谢谢!
来源: 互联网 发布时间:2015-02-23
本文导语: 错误:DBconn.java:7: expected public DBconn { ^ DBconn.java:26: ';' expected } ^ 2 errors 1 import java.sql.*; 2 public class DBconn { 3 String DBDriver="sun.jdbc.odbc.JdbcOdbcDriver"; 4 String ConnStr="jdbc:odbc:Test_DB"; 5 Co...
错误:DBconn.java:7: expected
public DBconn {
^
DBconn.java:26: ';' expected
}
^
2 errors
1 import java.sql.*;
2 public class DBconn {
3 String DBDriver="sun.jdbc.odbc.JdbcOdbcDriver";
4 String ConnStr="jdbc:odbc:Test_DB";
5 Connection conn=null;
6 ResultSet rs=null;
7 public DBconn {
8 try {
9 Class.forName(DBDriver);
10 }
11 catch(java.lang.ClassNotFoundException e) {
12 System.err.println("DBconn (): " + e.getMessage());
13 }
14 }
15 public ResultSet executeQuery(String sql) {
16 rs=null;
17 try {
18 conn = DriverManager.getConnection(ConnStr);
19 Statement stmt = conn.createStatement();
20 rs=stmt.executeQuery(sql);
21 }
22 catch(SQLException ex) {
23 System.err.println("aq.executeQuery:"+ex.getMessage());
24 }
25 return rs;
26 }
27 }
public DBconn {
^
DBconn.java:26: ';' expected
}
^
2 errors
1 import java.sql.*;
2 public class DBconn {
3 String DBDriver="sun.jdbc.odbc.JdbcOdbcDriver";
4 String ConnStr="jdbc:odbc:Test_DB";
5 Connection conn=null;
6 ResultSet rs=null;
7 public DBconn {
8 try {
9 Class.forName(DBDriver);
10 }
11 catch(java.lang.ClassNotFoundException e) {
12 System.err.println("DBconn (): " + e.getMessage());
13 }
14 }
15 public ResultSet executeQuery(String sql) {
16 rs=null;
17 try {
18 conn = DriverManager.getConnection(ConnStr);
19 Statement stmt = conn.createStatement();
20 rs=stmt.executeQuery(sql);
21 }
22 catch(SQLException ex) {
23 System.err.println("aq.executeQuery:"+ex.getMessage());
24 }
25 return rs;
26 }
27 }
|
第7行应该这样写:
public DBconn(){
public DBconn(){