Question

I am trying to store an image into db along with a string.i used the code given below

 File image = new File("c:/a1.jpg");
 String d=jTextField1.getText();
FileInputStream  fis 
 try {
        psmnt = con.prepareStatement("insert into c(name,pic) "+ "values(?,?)");
         psmnt.setString(1,d);
        fis = new FileInputStream(image);
         psmnt.setBinaryStream(2,fis,(int) (image.length()));
        psmnt.executeUpdate();
     }
catch().....

I tried a lot.But still am getting error " unimplemented or unreasonable conversion requested" .Can anyone help to solve this?pic is declared as blob datatype.Thank you.

No correct solution

OTHER TIPS

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



      try {  
         String sid="orcl";
         String username="user";
         String password= "pass";
        DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());  
         Connection connection = DriverManager.getConnection(  
                "jdbc:oracle:thin:@localhost:1521:"+sid, username, password);  

        //Statement statement = connection.createStatement();  
           File image = new File("c:/a1.jpeg");
           String d= "the pics";
           FileInputStream  fis ;
           fis = new FileInputStream(image);

          String query = " insert into c(name,pic)values(?,?)";
          PreparedStatement preparedStmt = connection.prepareStatement(query);
           //System.out.println("Data is inserted:");
           preparedStmt.setString(1, d);
           preparedStmt.setBinaryStream(2,fis,(int) (image.length()));

            // execute the preparedstatement
           preparedStmt.execute();
           connection.close(); 
   } catch (Exception e) {  
        e.printStackTrace();  
     }  
   System.out.println("Data is inserted:");

}

I suppose you have added oracle jar ojdbc14.jar in your project

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top