日期:2014-05-20  浏览次数:20640 次

Java连接MySQL数据库的问题
import   java.sql.*;

public   class   TestSQL{
            public   static   void   main(String   args[]){
                    try{  
                    Class.forName( "com.mysql.jdbc.Driver ");//驱动的名称
                            Connection   c   =   DriverManager.getConnection( "jdbc:mysql://localhost/justin?user=root&password=root ");//访问的数据库的帐号密码
                            Statement   s   =   c.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,   ResultSet.CONCUR_UPDATABLE);
                            ResultSet   r   =   s.executeQuery( "select   name,   birDay   from   justin ");//执行SQL语句
                           
                            r.absolute(2);
                            r.updateString( "name ",   "BaoBao ");
                            r.updateRow();
                           
                            while(r.next()){                          
                                    System.out.println(r.getString( "name "));//返回的结果
                            }
                            s.close();    
                    }catch(Exception   e){
                    e.printStackTrace();
                      }   //捕获异常
          }
}  

在Eclipse环境下,运行出错:
com.mysql.jdbc.NotUpdatable:   Result   Set   not   updatable.This   result   set   must   come   from   a   statement   that   was   created   with   a   result   set   type   of   ResultSet.CONCUR_UPDATABLE,   the   query   must   select   only   one   table,   and   must   select   all   primary   keys   from   that   table.   See   the   JDBC   2.1   API   Specification,   section   5.6   for   more   details.

可是我已经在createStatement加了ResultSet.CONCUR_UPDATABLE字段了阿?
我的jar包是:mysql-connector-java-3.0.9-stable-bin.jar

------解决方案--------------------
你用MYSQL的版本是多少啊?
------解决方案--------------------