请问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)
[最优解释]
可能是多了或少了括弧
[其他解释]
少了个大括号
[其他解释]
真的是少了个大括号。。。
[其他解释]
这都是不细心的结果~
[其他解释]
删些代码测试下
[其他解释]
必须是少了个}
[其他解释]
你写代码没有用工具吗?
如果用工具,它会提示你的呀。
[其他解释]