异常:ORA-01465:无效的十六进制数

wgmfuz8q  于 2022-09-18  发布在  Java
关注(0)|答案(2)|浏览(188)

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

我试过这个

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

efzxgjgh1#

试试看

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();
    }
z18hc3ub

z18hc3ub2#

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

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

相关问题