| |

VerySource

 Forgot password?
 Register
Search
View: 741|Reply: 2

About inserting Clob type data into the Oracle database! How to convert String type data to Clob type?

[Copy link]

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-2-23 07:30:02
| Show all posts |Read mode
The problem is as follows:
  public int insertForm () {
        String strsql = "";
        String strtime = "";
        try {
            Connection conn = db.getConnection ();
            strtime = db.getCurrentDate ("yyyy-MM-dd HH: mm: ss");
            strsql = "insert into productor (cpmc, bbh, cpgn, lbid, moreinfo) values ​​(?,?,?,?,?)"; // where cpgn and moreinfo are Clob-type fields in the database

            PreparedStatement pstmt = conn.prepareStatement (strsql);
            pstmt.setString (1, form.getCpmc ());
            pstmt.setString (2, form.getBbh ());

             oracle.sql.CLOB clob1 = oracle.sql.CLOB.createTemporary (conn, false, oracle.sql.CLOB.DURATION_CALL);
             clob1.putString (1, form.getContent ()); // Convert form.getContent () (its value is String) into a CLOB type and insert it into the database
             pstmt.setClob (3, clob1);
             pstmt.setInt (4, Integer.parseInt (form.getCplx ()));
             
            oracle.sql.CLOB clob2 = oracle.sql.CLOB.createTemporary (conn, false, oracle.sql.CLOB.DURATION_CALL);
             clob2.putString (1, form.getXxxx ()); // Convert form.getXxxx () (its value is String) into CLOB type and insert it into the database
            pstmt.setClob (5, clob2);
            pstmt.executeUpdate ();
            conn.commit ();
            pstmt.close ();
            db.close ();
        } catch (Exception e) {
            db.rollback ();
            e.printStackTrace ();
            return 2;
         e.printStackTrace ();
        } finally {
            db.close ();
        }
        return 0;
    }

An error occurred while the program was running! java.sql.SQLException: Cannot read more data from the socket
I don't know what's wrong! Please master to see if there is a problem with the program! speed. . . .
Reply

Use magic Report

0

Threads

11

Posts

10.00

Credits

Newbie

Rank: 1

Credits
10.00

 China

Post time: 2020-5-7 14:00:01
| Show all posts
Change your code to the following:
// Create and instantiate a CLOB object
CLOB clob = new CLOB ((OracleConnection) con);
clob = oracle.sql.CLOB.createTemporary ((OracleConnection) con, true, 1);
// Assign the CLOB object
clob.putString (1, form.getContent ());
OracleConnection OCon = (OracleConnection) con;
OraclePreparedStatement pstmt = (OraclePreparedStatement) OCon.prepareCall (strSql);

// This one, you see it, the key, setCLOB
pstmt.setClob (2, clob);
Reply

Use magic Report

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

 Author| Post time: 2020-5-13 22:45:01
| Show all posts
Could you help me change my program? Let me see the post! Don't quite understand your intentions!
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list