0

我正在尝试在数据库中保存值,但出现此错误

我试过这个

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         

    try {
        // TODO add your handling code here:
        captureScreen("img.jpg");
    } catch (Exception ex) {
        Logger.getLogger(frontendUI.class.getName()).log(Level.SEVERE, null, ex);
    }
    try {
        Class.forName("oracle.jdbc.driver.OracleDriver");
        System.out.println("driver  loaded");
    }
    catch(ClassNotFoundException ex) {
        System.out.println("driver not loaded");
    }

    String URL = "jdbc:oracle:thin:@localhost:1521:xe";
    String Username = "system";
    String Password = "toushif";
    try { 
        con = DriverManager.getConnection(URL,Username,Password);
        st=(Statement) con.createStatement();
        String sql="insert into TOU3(file123) values('"+abc+"')";
        st.executeUpdate(sql);
    }                                        
    catch(Exception e) {
        e.printStackTrace();
    }

/**
 * @param args the command line arguments
 */
}
4

2 回答 2

0

尝试

    try { 
        con = DriverManager.getConnection(URL,Username,Password);
        st=(Statement) con.createStatement();
        String sql="insert into TOU3(file123) values("+abc+")";
        st.executeUpdate(sql);
    }                                        
    catch(Exception e) {
        e.printStackTrace();
    }
于 2013-10-11T09:20:57.853 回答
0

如果要将字符串插入 BLOB 类型,则需要使用getBytes()

// ex:
String abc = "very long string";
// file123 is BLOB column
String query = "insert into TOU3(file123) values(" + abc.getBytes() + ")";
于 2020-04-15T20:49:49.267 回答