用MyEclipse建了个jdbc访问MySql的程序,但是运行时会跳出一个窗口,并且显示不了结果,谁能告诉我原因
publicclassJdbcTest{privatestaticStringdriver="org.gjt.mm.mysql.Driver";privatestatic...
public class JdbcTest {
private static String driver = "org.gjt.mm.mysql.Driver";
private static String URL = "jdbc:mysql://localhost:3306/test";
private static String username = "root";
private static String password = "123456";
public static void main(String[] args) throws SQLException {
// TODO Auto-generated method stub
try {//加载驱动
Class.forName(driver);
//创建连接
Connection con = DriverManager.getConnection(URL,username,password);
//创建连接上的statement
Statement stmt = con.createStatement();
//发起一个查询
ResultSet res = stmt.executeQuery("select * from userinfor");
//显示查询结果
while(res.next()){
int id = res.getInt("id");
String name = res.getString("name");
System.out.println(id+name);
}
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
} 展开
private static String driver = "org.gjt.mm.mysql.Driver";
private static String URL = "jdbc:mysql://localhost:3306/test";
private static String username = "root";
private static String password = "123456";
public static void main(String[] args) throws SQLException {
// TODO Auto-generated method stub
try {//加载驱动
Class.forName(driver);
//创建连接
Connection con = DriverManager.getConnection(URL,username,password);
//创建连接上的statement
Statement stmt = con.createStatement();
//发起一个查询
ResultSet res = stmt.executeQuery("select * from userinfor");
//显示查询结果
while(res.next()){
int id = res.getInt("id");
String name = res.getString("name");
System.out.println(id+name);
}
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
} 展开
展开全部
检查你的配置文件有没有写错
追问
哪里的配置文件?这个就是java文件,我没有用Hiberate框架的
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询