Results 1 to 1 of 1
  1. #1
    ak88 is offline Member
    Join Date
    Jul 2009
    Posts
    17
    Rep Power
    0

    Post how to insert a ole object using java

    hi

    I have been trying to insert a picture into my access database

    My database is sundar.mdb and ma table is adf which has only one column of the type OLEObject
    I have used the code

    Java Code:
    import java.sql.*;
    import java.io.*;
    
    class a
    {
    	public static void main(String arg[])
    	{
    		try
    		{
    			Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    			String filename = "d:/sundar/sundar.mdb";
    			String database = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=";
    			database+= filename.trim() + ";DriverID=22;READONLY=true}"; // add on to the end 
    			Connection con = DriverManager.getConnection( database ,"arun",""); 
    			PreparedStatement stmt=con.prepareStatement("insert into adf values (?)");
    			File imgfile = new File("C:\\ak.jpg");
    			FileInputStream fin = new FileInputStream(imgfile);
    			stmt.setBinaryStream(1,fin,(int)imgfile.length());
    		        stmt.executeUpdate();
    		        System.out.println("Data inserted");
    		}catch(Exception e)
    		{
    			System.out.println(e);
    		}
    	}
    }

    Output comes as
    Data inserted
    but when i verify the table data is not inserted......
    Help me out to solve this problem

    Thanks in advance
    Last edited by Fubarable; 01-05-2010 at 06:12 PM. Reason: code tags added

Similar Threads

  1. Replies: 2
    Last Post: 11-26-2010, 02:12 AM
  2. insert java code to SQL
    By rashidzamani in forum JDBC
    Replies: 3
    Last Post: 08-18-2009, 01:07 PM
  3. Cannot insert duplicate key row in object
    By losintikfos in forum New To Java
    Replies: 3
    Last Post: 05-07-2009, 09:43 AM
  4. Replies: 3
    Last Post: 02-28-2009, 09:17 AM
  5. How to insert java Object in oracle database
    By Thilkumar82 in forum Advanced Java
    Replies: 9
    Last Post: 08-13-2008, 11:33 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
  •