标题:用结果集插入longtext为何出错?
只看楼主
msl12
Rank: 1
等 级:新手上路
帖 子:152
专家分:0
注 册:2015-2-6
结帖率:25%
 问题点数:0 回复次数:2 
用结果集插入longtext为何出错?
代码如下:
------------------------------------------------------------
import *;
import java.sql.*;

public class Test17 {
    public static String URL="jdbc:mysql://localhost:3306/lll";
    public static String USER="root";
    public static String KEY="1";

    public static void main(String args[]) throws Exception {
        Connection con=DriverManager.getConnection(URL, USER, KEY);
        String sql="select * from test2";
        PreparedStatement ps=con.prepareStatement(sql, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
        ResultSet rs=ps.executeQuery();
        rs.moveToInsertRow();
        File file=new File("C:\\Users\\lll\\Desktop\\JAVA\\long.txt");
        rs.updateString("name", "small_test2");
        rs.updateAsciiStream("note", new FileInputStream(file), file.length());    /*显示这里出错?

    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, can not use functions and must select all primary keys from that table. See the JDBC 2.1 API Specification, section 5.6 for more details.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, can not use functions and must select all primary keys from that table. See the JDBC 2.1 API Specification, section 5.6 for more details.*/

        rs.insertRow();
        
        rs.close();
        ps.close();
        con.close();
    }
   
    public static void print(ResultSet rs) throws Exception {
        while (rs.next()) {
            System.out.println("编号:"+rs.getString(1));
            System.out.println("姓名:"+rs.getString(2));
            System.out.println("年龄:"+rs.getString(3));
            System.out.println("性别:"+rs.getString(4));
            System.out.println("生日:"+rs.getString(5));
            System.out.println();
        }
    }
}
2015-11-12 19:42
msl12
Rank: 1
等 级:新手上路
帖 子:152
专家分:0
注 册:2015-2-6
得分:0 
再顶一下。
2015-11-12 23:30
msl12
Rank: 1
等 级:新手上路
帖 子:152
专家分:0
注 册:2015-2-6
得分:0 
再顶再顶
2015-11-14 12:11



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-459138-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014563 second(s), 7 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved