java.sql.SQLException:ORA-01465:十六进制数无效

时间:2013-10-11 09:05:00

标签: java sql oracle

我正在尝试在数据库中保存价值,但我收到此错误

我试过这个

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
 */
}

2 个答案:

答案 0 :(得分: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();
    }

答案 1 :(得分:0)

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

// ex:
String abc = "very long string";
// file123 is BLOB column
String query = "insert into TOU3(file123) values(" + abc.getBytes() + ")";