Results 1 to 12 of 12
  1. #1
    sridarshan is offline Member
    Join Date
    Jun 2010
    Posts
    9
    Rep Power
    0

    Default how to store images in access database

    for my new project ,i wanted to store images in access db,
    the access table which i created is of from
    images|imageDate|hostIP

    here's the code which i wrote
    Java Code:
    FileInputStream fis = new FileInputStream(ScreenShot);
                Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                Connection con = DriverManager.getConnection("jdbc:odbc:screenshots");
                PreparedStatement ps = con.prepareStatement("insert into images(images,imageDate,HostIP) values(?,?,?)");
                String imageDate = d.toString().substring(8,10)+d.toString().subSequence(4, 7)+d.toString().substring(24)+"#"+d.toString().substring(11, 13)+":"+d.toString().substring(14, 16);
                ps.setBinaryStream(1,fis,ScreenShot.length());
                
                ps.setString(2, imageDate);
                ps.setString(3,ipad.trim());
                int a = ps.executeUpdate();
                if(a!=0){System.out.println("Image successfully inserted");}
                else{System.out.println("Image insertion failed");}
                ps.close();
                con.close();

    everytime i run this code,i get sqlexception of code 17

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    The best way to store images is in binary format, the way you tried actually. But the MS Access is not reliable for that. Why don't you use SQL for that.

    Do you know about blob type? Blob, treated blocks of bits and able to deals with chunks.

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by sridarshan View Post
    everytime i run this code,i get sqlexception of code 17
    Can you post the complete error message here to see?

  4. #4
    sridarshan is offline Member
    Join Date
    Jun 2010
    Posts
    9
    Rep Power
    0

    Default

    Isnt what im using right now blob?if not ,how do i use blob?
    I have limited resources on the project,so have to stick to ms access

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,817
    Rep Power
    19

    Default

    Can you give the full exception?
    Preferably with stack trace.

    What column type is the image column?

    And, even with limited resources, there's always Derby.

  6. #6
    sridarshan is offline Member
    Join Date
    Jun 2010
    Posts
    9
    Rep Power
    0

    Default

    Quote Originally Posted by Tolls View Post
    Can you give the full exception?
    Preferably with stack trace.

    What column type is the image column?

    And, even with limited resources, there's always Derby.
    here's the SQLException.toString outout
    Java Code:
    java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver]COUNT field incorrect
    and here' the stack trace
    Java Code:
    sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6957)
    sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7114)
    sun.jdbc.odbc.JdbcOdbc.SQLExecute(JdbcOdbc.java:3149)
    sun.jdbc.odbc.JdbcOdbcPreparedStatement.execute(JdbcOdbcPreparedStatement.java:216)
    sun.jdbc.odbc.JdbcOdbcPreparedStatement.executeUpdate(JdbcOdbcPreparedStatement.java:138)
    server.getScreen.run(getScreen.java:66)
    java.lang.Thread.run(Thread.java:619)

    the column type of image is OLE object.. I havent worked on derby till now,but will look into it..

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,817
    Rep Power
    19

    Default

    Are you sure it's the image causing the problem?
    Your date column, is it a DATE in Access?
    If so why not setDate, rather than going through all that bizarre conversion to a String? If it has to be a String then use SimpleDateFormat...it's a lot easier to read.

  8. #8
    sridarshan is offline Member
    Join Date
    Jun 2010
    Posts
    9
    Rep Power
    0

    Default

    i'm pretty sure its the image ,because i changed the data type of image to text without changing anything in table,and entered text to it,it got stored,,,so thats why i think its the image which is causing the trouble..
    and the imageDate data type in table is string,so no problem there

  9. #9
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,817
    Rep Power
    19

    Default

    OK, that's my second suggestion out the way then...:)

    I do wonder if the jdbc-odbc bridge is having problems...it is a rather rubbish driver. I've not had to do anything serious with Access before (well, there was an internal phone directory a decade ago, but the less said about that the better), but I do know that driver isn't really intended for serious work.

  10. #10
    sridarshan is offline Member
    Join Date
    Jun 2010
    Posts
    9
    Rep Power
    0

    Default

    thanks anyways tolls
    looks like ive gotta change my database to oracle or derby..

  11. #11
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,817
    Rep Power
    19

    Default

    That would be my recommendation. Access is a bit of a toy.
    I wouldn't rely on Derby for anything too heavy duty...good for embedded stuff, but I'd go for a heftier db if you're doing something more web based (multiple connections).

  12. #12
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

Similar Threads

  1. How do I store images in a zip file in Java
    By mglover in forum Advanced Java
    Replies: 1
    Last Post: 06-11-2010, 03:53 PM
  2. How can i store ArrayList objects in Access database
    By frankycool in forum Advanced Java
    Replies: 3
    Last Post: 11-04-2009, 06:55 AM
  3. Replies: 2
    Last Post: 02-11-2009, 04:43 AM
  4. Replies: 0
    Last Post: 07-13-2008, 01:47 PM
  5. Replies: 1
    Last Post: 08-07-2007, 07:51 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •