com.ibm.db2.jcc.b.SqlException: End of Stream prematurely reached while reading Reader, parameter #2.  Remaining data has been padded with 0x0.
请各位帮忙指点一下!

解决方案 »

  1.   

    程序清单如下;package opdb2;public class db2Clob { /**
     * @param args
     */
    Connection conn;

    public db2Clob(){     try {
    Class.forName("com.ibm.db2.jcc.DB2Driver").newInstance();
    System.out.println("ok");
    String  url=  "jdbc:db2://172.20.68.75:50000/shihua" ; 
                        String  user="db2admin";  
                        String  password="shihua";
    conn= DriverManager.getConnection(url,user,password);  
    System.out.println("----driver--start4----");

         } catch (SQLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } catch (InstantiationException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } catch (IllegalAccessException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } catch (ClassNotFoundException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();


    }
    public void setClob(){
    try {
    PreparedStatement pstm = conn.prepareStatement("insert                into TEST_CLOB(ID,CLOB) values(?,?)");
    File bf=new File("E:\\MyProgram\\image\\my.txt");       
            InputStreamReader bin=new InputStreamReader(new FileInputStream           (bf));
            pstm.setInt(1,7);
          
            
            pstm.setCharacterStream(2, bin, (int)bf.length());
        
    pstm.executeUpdate();

    pstm.close();
    bin.close();
    System.out.println("CLOB成功插入");
    } catch (SQLException e) {
    System.out.println("------sql");
    // TODO Auto-generated catch block
    e.printStackTrace();
    } catch (FileNotFoundException e) {
    // TODO Auto-generated catch block
    System.out.println("========");
    e.printStackTrace();
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }

    }
    public void getClob(){
    try {
    Statement st=conn.createStatement();
    ResultSet rs=st.executeQuery("select CLOB from TEST_CLOB");
    while(rs.next()){
    Reader in=rs.getCharacterStream("CLOB");
    int i=0;
        File cf=new File("e:\\copy.txt");
        OutputStreamWriter cout=new OutputStreamWriter(new FileOutputStream(cf));
        while( (i=in.read())!=-1){
                    cout.write(i);  
                
        System.out.println(i);
        }
        System.out.println(y);
        in.close();
        cout.close();
    System.out.println("CLOB成功取出");
    }
    st.close();
    } catch (SQLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } catch (FileNotFoundException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }

    }

     public static void main(String[] args) {
    // TODO Auto-generated method stub
    db2Clob b=new db2Clob();
    //b.setBlob();
    try {
    b.setClob();
    System.out.println("-----ok-insert------");
    b.getClob();
    } catch (Exception e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } }}
    结果就抛出上面的错误了:
    谢谢大侠们