'java.sql.SQLException: ORA-01465: invalid hex number
i am trying to save value in database but i am getting this error
i tried this
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
*/
}
Solution 1:[1]
try
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();
}
Solution 2:[2]
if you are inserting string into BLOB type you need to use getBytes()
// ex:
String abc = "very long string";
// file123 is BLOB column
String query = "insert into TOU3(file123) values(" + abc.getBytes() + ")";
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | sunysen |
| Solution 2 | KhogaEslam |
