程序写完,测试出错了,求助
运行结果出错了,这个怎么解决?
运行结果出错了,这个怎么解决?
2016-01-09
问题解决了。
解决方法:mysql重装之前注意到安装路径下,彻底删掉有关文件,然后重新导入.jar文件,add path
代码如下:
package com.imooc.db;
import java.sql.DriverManager;
import java.sql.ResultSet;
import com.mysql.jdbc.Connection;
import com.mysql.jdbc.Statement;
public class DBUtil {
public static void main(String[] args)throws Exception{
Class.forName("com.mysql.jdbc.Driver");
Connection conn=(Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/imooc","root","123");
Statement stmt=(Statement) conn.createStatement();
ResultSet rs=stmt.executeQuery("select user_name,age from imooc_goddess");
while(rs.next()){
System.out.println(rs.getString("user_name")+","+rs.getInt("age"));
}
举报