String rq = "select surname from basicInfo";
你的sql语句不是选者的surname吗?当然就没有name字段了
改成这样String rq = "select name from basicInfo";

解决方案 »

  1.   

    or 
    String rq = "select surname as name from basicInfo";
      

  2.   

    首先我要感谢楼上大哥的帮助.不过我把它改了还是不行.
    import java.sql.*;
    public class MySQLTest {
       public static void main(String[] args){
       Connection connect = null;
       ResultSet resultSet = null;
       try{
          Class.forName(
                           com.mysql.jdbc.Driver").newInstance();
                }catch(Exception e){
         System.out.println("Unable to load driver>");
         e.printStackTrace();
       }
       try{
       Statement statement = null;
       String username = "root";
       String password = "";
       String url = "jdbc:mysql://localhost/cupdb";
       connect = DriverManager.getConnection(
                                url,username,password);  
       String rq = "select name from basicInfo";
                statement = connect.createStatement();
                resultSet = statement.executeQuery(rq);            
                while(resultSet.next()){
                String name = resultSet.getString("name");
                System.out.println("Name"+name);
               }
               statement.close();
       }catch(SQLException e){
       e.printStackTrace();
       }
          finally {
           if(connect != null){
           try{
           connect.close();
           }catch(Exception e){
           e.printStackTrace();
           }
           }
    }
       }
    } java.sql.SQLException: Column 'name' not found.
    at com.mysql.jdbc.ResultSet.findColumn(ResultSet.java:2368)
    at com.mysql.jdbc.ResultSet.getString(ResultSet.java:1901)
    at MySQltest.main(MySQltest.java:26)
    我敏思不的其解,还望高手指教,谢谢!
      

  3.   

    basicInfo是里面的一张表,包含name,price 你的金mysql看看到底表basicInfo有没有name这个字段???
      

  4.   

    程序正常的 com.mysql.jdbc.Driver").newInstance(); 要加以个"再前面就可以了结果也是正常的你的进mysql看看到底表basicInfo有没有name这个字段???估计没有吧!CREATE TABLE `basicInfo` (`id` INT UNSIGNED NOT NULL AUTO_INCREMENT, `name` VARCHAR (20) NOT NULL, `price` VARCHAR (10) DEFAULT '0' NOT NULL, PRIMARY KEY(`id`)) ;INSERT INTO basicinfo (id, name, price) VALUES (NULL, 'coolwind1', '0');
    INSERT INTO basicinfo (id, name, price) VALUES (NULL, 'coolwind2', '0');
    INSERT INTO basicinfo (id, name, price) VALUES (NULL, 'coolwind3', '0');
    INSERT INTO basicinfo (id, name, price) VALUES (NULL, 'coolwind4', '0');
    import java.sql.*;
    public class MySQLTest {
       public static void main(String[] args){
       Connection connect = null;
       ResultSet resultSet = null;
       try{
          Class.forName(
                           "com.mysql.jdbc.Driver").newInstance();
                }catch(Exception e){
         System.out.println("Unable to load driver>");
         e.printStackTrace();
       }
       try{
       Statement statement = null;
       String username = "root";
       String password = "";
       String url = "jdbc:mysql://localhost/test";
       connect = DriverManager.getConnection(
                                url,username,password);  
       String rq = "select name from test.basicInfo";
                statement = connect.createStatement();
                resultSet = statement.executeQuery(rq);            
                while(resultSet.next()){
                String name = resultSet.getString("name");
                System.out.println("Name"+name);
               }
               statement.close();
       }catch(SQLException e){
       e.printStackTrace();
       }
          finally {
           if(connect != null){
           try{
           connect.close();
           }catch(Exception e){
           e.printStackTrace();
           }
           }
    }
       }
    }
      

  5.   

    没有问题啊!嗬嗬!你再看看???
    C:\Documents and Settings\Administrator\桌面>mysql -uroot -p
    Enter password: ********
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 26 to server version: 4.0.17-nt-logType 'help;' or '\h' for help. Type '\c' to clear the buffer.mysql> use test;
    Database changed
    mysql> desc basicinfo;
    +-------+------------------+------+-----+---------+----------------+
    | Field | Type             | Null | Key | Default | Extra          |
    +-------+------------------+------+-----+---------+----------------+
    | id    | int(10) unsigned |      | PRI | NULL    | auto_increment |
    | name  | varchar(20)      |      |     |         |                |
    | price | varchar(10)      |      |     | 0       |                |
    +-------+------------------+------+-----+---------+----------------+
    3 rows in set (0.00 sec)mysql> select * from basicinfo;
    +----+-----------+-------+
    | id | name      | price |
    +----+-----------+-------+
    |  1 | coolwind1 | 0     |
    |  2 | coolwind2 | 0     |
    |  3 | coolwind3 | 0     |
    |  4 | coolwind4 | 0     |
    +----+-----------+-------+
    4 rows in set (0.00 sec)mysql> exit
    ByeC:\Documents and Settings\Administrator\桌面>
    C:\Documents and Settings\Administrator\桌面>type MySQLTest.java
    import java.sql.*;
    public class MySQLTest {
            public static void main(String[] args){
                    Connection connect = null;
                    ResultSet resultSet = null;
                    try{
                       Class.forName(
                           "com.mysql.jdbc.Driver").newInstance();
                     }catch(Exception e){
                      System.out.println("Unable to load driver>");
                      e.printStackTrace();
                    }
                    try{
                            Statement statement = null;
                            String username = "root";
                            String password = "";
                            String url = "jdbc:mysql://localhost/test";
                            connect = DriverManager.getConnection(
                                url,username,password);
                            String rq = "select name from test.basicInfo";
                statement = connect.createStatement();
                resultSet = statement.executeQuery(rq);
                while(resultSet.next()){
                String name = resultSet.getString("name");
                System.out.println("Name"+name);
               }
               statement.close();
                    }catch(SQLException e){
                    e.printStackTrace();
                    }
               finally {
                    if(connect != null){
                            try{
                                    connect.close();
                            }catch(Exception e){
                                    e.printStackTrace();
                            }
                    }
            }
            }
    }
    C:\Documents and Settings\Administrator\桌面>javac MySQLTest.javaC:\Documents and Settings\Administrator\桌面>java MySQLTest
    Namecoolwind1
    Namecoolwind2
    Namecoolwind3
    Namecoolwind4C:\Documents and Settings\Administrator\桌面>
      

  6.   

    对了,如果你不建议的话,你加我的QQ吧49953755
    或者你给我你的QQ号,我来加你
      

  7.   

    估计是你系统的问题,具体哪里有毛病,需要你自己去check.