JAVA代码找错

来源:百度知道 编辑:UC知道 时间:2024/09/22 07:46:16
import java.sql.*;
public class HelloJdbc {
private String drive="org.git.mm.mysql.Driver";
private String url="jdbc:mysql://localhost:3306/mydatabase";
private Connection conn=null;//与特定数据库的连接会话
public HelloJdbc(){
try {
Class.forName(drive);

conn=DriverManager.getConnection(url,"root","root");
} catch (SQLException e) {

System.out.println(e.getMessage());

} catch (ClassNotFoundException e) {

System.out.println(e.getMessage());

}
public Connection getconn(){
return this.conn;

}
public void handleUse(Connection conn){
try{
String sql="select*from users";

int i=1;
Statement state=conn.createStatement();
ResultSet rs=state.executeQuery(sql);
while(rs.next()){
i++;
System.out.println("第"

我看了一下,你的代码没有逻辑的错误,就是多了一个"}"少了一个"}"
public HelloJdbc(){
try {
Class.forName(drive);

conn=DriverManager.getConnection(url,"root","root");
} catch (SQLException e) {

System.out.println(e.getMessage());

} catch (ClassNotFoundException e) {

System.out.println(e.getMessage());
} // 这里少了一个"}",加上就好了
}

public void handleUse(Connection conn){
try{
String sql="select*from users";

int i=1;
Statement state=conn.createStatement();
ResultSet rs=state.executeQuery(sql);
while(rs.next()){
i++;
System.out.println("第"+i+"行记录");
System.out.println("表单数据"+rs.getString(3));
System.out.println("表单数据"+rs.getString(3));
}

}catch (SQLException e) {
e.prin