本帖最后由 田建 于 2012-7-1 18:53 编辑
代码如下,读取数据库的数据,不知是什么问题,求大神相助,,数据库的安装加数据库驱动再加这个问题已经弄了一上午了!- package cn.itcast.jdbc;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.Statement;
- public class Base {
- public static void main(String[] args)throws Exception{
- test();
- }
- static void test()throws Exception{
- Class.forName("com.mysql.jdbc.Driver");
- Connection conn=DriverManager.getConnection(
- "jdbc:mysql://localhost:3306/jdbc","root","admin");
- Statement st=conn.createStatement();
- ResultSet rs=st.executeQuery("select*from user");
- while(rs.next()){
- System.out.println(rs.getObject(1)+"\t"+rs.getObject(2)+"\t"+
- rs.getObject(3));
- }
- rs.close();
- st.close();
- conn.close();
- }
- }
复制代码 问题显示如下!
Exception in thread "main" com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'jdbc.user' doesn't exist
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.Util.getInstance(Util.java:386)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1052)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4096)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4028)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2490)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2651)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2677)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2627)
at com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1556)
at cn.itcast.jdbc.Base.test(Base.java:17)
at cn.itcast.jdbc.Base.main(Base.java:10) |
|