I'm trying to upload a file to oracle database but I got this error:
java.sql.SQLException: ORA-01460: unimplemented or unreasonable conversion requested
This is my code to insert the file:
b2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
Connection conn;
FileInputStream fis = new FileInputStream(file);//From JFileChooser
String url = "*******************";
String u = "***********";
String p = "**********";
Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection(url, u, p);
System.out.println("Ligação efectuada com sucesso");
PreparedStatement pstmt = conn.prepareStatement(
"insert into tableX(file, name) values ( ?, ?)");
pstmt.setString(2, file.getName());
pstmt.setBinaryStream(1, fis, (int) file.length());;
pstmt.executeUpdate();
JOptionPane.showMessageDialog(null, "Uploaded successfully to database");
pstmt.close();
conn.close();
} catch (Exception ex) {
System.out.println(ex);
}
}
});
The file source is from JFileChooser
:
b1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JFileChooser chooser = new JFileChooser();
int returnVal = chooser.showOpenDialog(null);
if (returnVal == JFileChooser.APPROVE_OPTION) {
file = chooser.getSelectedFile();
text.setText(file.getPath());
}
}
});
This error is problem of the code or a problem from Oracle JDBC driver
?