-2

I am developing a simple jdbc program. How can I use the extended dll functionality in jdbc program.

This is my code:

import java.sql.*;

public class jdbc2
{

    // JDBC driver name and database URL
    static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
    static final String DB_URL = "jdbc:mysql://localhost:3306/somesh";

    //  Database credentials
    static final String USER = "root";
    static final String PASS = "";

    public static void main(String[] args)
    {
        Connection conn = null;
        Statement stmt = null;
        try{
            //STEP 2: Register JDBC driver
            Class.forName("com.mysql.jdbc.Driver");

            //STEP 3: Open a connection
            // System.out.println("Connecting to database...");
            conn = DriverManager.getConnection(DB_URL,USER,PASS);
            System.out.println("Connecting to database...");
            //STEP 4: Execute a query
            System.out.println("Creating statement...");
            stmt = conn.createStatement();
            String sql;
            sql = " select id,image from images1 ";
            ResultSet rs  = stmt.executeQuery(sql);

            //STEP 5: Extract data from result set
            while(rs.next())
            {
                //Retrieve by column name
                System.out.println("\n");
                int no = rs.getInt("id");
                System.out.print("\t USER_I_ID: " +no);
                /*String std_name = rs.getString("name");
                System.out.print(" \t First_name : " + std_name);
                String std_course = rs.getString("course");
                System.out.print(" \t course : " + std_course);*/
                Blob std_image = rs.getBlob("image");
                System.out.print(" \t std_images : SS" + std_image);
            }
        }

        catch(SQLException se)
        {
            //Handle errors for JDBC
            se.printStackTrace();
        }catch(Exception e)
        {
            //Handle errors for Class.forName
            e.printStackTrace();
        }finally
        {
            //finally block used to close resources
            try{
                if(stmt!=null)
                    stmt.close();
            }catch(SQLException se2){
            }// nothing we can do
            try{
                if(conn!=null)
                    conn.close();
            }catch(SQLException se){
                se.printStackTrace();
            }//end catch try

        }//end finally

    }//end main
}//end FirstExample

now i use to the dll function is:

int AddFpUser ( BOOL bSorC, BYTE FacID, int nTmlSize, BYTE *pTemplate, const char *UserName, const char *UserID, BYTE GroupID, BYTE FingerID, BYTE UserType ).

so please use this function that above program . That function definition is contain to store the images.. so please give the answer for that . Thank you for helping

Igor Jerosimić
  • 13,621
  • 6
  • 44
  • 53
somesh
  • 81
  • 1
  • 1
  • 4

1 Answers1

0

Looks to me like a simple db insert operation.

First of All: Why are you trying to use a "c" function for this operation. What is written in this function which java doesn't provide. If nothing, then re-write the same function in java. Its just like messing with languages for no good reason.

Secondly, I don't think that creating a jdbc connection here, is of any use, because if you want to use a function written in dll, it should create its own db-connection.

For using dll functions have a look at JNI.

http://docs.oracle.com/javase/6/docs/technotes/guides/jni/

Himanshu Bhardwaj
  • 4,038
  • 3
  • 17
  • 36
  • i want to store images in to fs 21 reader.that why reason i am getting the images from database and store those images into fs 21 . that reason i am trying to use that jdbc program with dll fuction . so how to salve this problem. – somesh Apr 01 '13 at 05:47
  • Ok So if I understand you correctly you are using the JDBC program to read images from database, and the dll to store into fs21. Have a look at this: http://stackoverflow.com/questions/7593334/how-to-call-c-from-java – Himanshu Bhardwaj Apr 01 '13 at 05:53