日期:2014-05-19  浏览次数:20643 次

请问JAVA在连接Mysql时候括号错误
package MySqlTest;
import java.sql.*;

public class testMysql {
public static void main(String[] args) {

Connection conn = null;

Statement ste = null;

try {

//加载驱动

Class.forName("com.mysql.jdbc.Driver");
System.out.println("加载驱动成功");
}catch(ClassNotFoundException e){
System.out.println("加载驱动失败");
e.printStackTrace();
}
//创建Connection对象
        try{
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/mysqltest", "root", "227227");
ste=conn.createStatement();
System.out.println("数据库连接成功");
        }catch(ClassNotFoundException e){
         System.out.println("数据库连接失败");
e.printStackTrace();
        
        }

        //编写Sql语句

String sql = "select name,id from testmysql";



//执行sql语句

ResultSet rs = ste.executeQuery(sql);

while(rs.next()){

int id = rs.getInt("id");

String name = rs.getString("name");

System.out.println("id:"+id+"name:"+name);

}

}《错误在这个括号》

错误信息是Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
Syntax error, insert "}" to complete ClassBody

at MySqlTest.testMysql.main(testMysql.java:52)



------最佳解决方案--------------------
可能是多了或少了括弧
------其他解决方案--------------------
少了个大括号
------其他解决方案--------------------
真的是少了个大括号。。。
------其他解决方案--------------------
这都是不细心的结果~
------其他解决方案--------------------
删些代码测试下
------其他解决方案--------------------
必须是少了个}
------其他解决方案--------------------
你写代码没有用工具吗?
如果用工具,它会提示你的呀。
------其他解决方案--------------------


引用:
必须是少了个}
 尝试删除了}和增加} 还是报错