读书人

请教JAVA在连接Mysql时候括号异常

发布时间: 2012-12-14 10:33:08 作者: rapoo

请问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)



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


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

读书人网 >J2EE开发

热点推荐