Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Database (http://www.go4expert.com/forums/database-forum/)
-   -   Need help with passing user defined variable in SQLJ (http://www.go4expert.com/forums/help-passing-user-defined-variable-sqlj-t27971/)

redkryptonite 7Mar2012 11:45

Need help with passing user defined variable in SQLJ
 
Hi i need to the user to input the variables ( "name" and "id" ) and by prepared statement they are passed to sql query. plz help ... and i need to know how to copy the output in ResultSet to a variable so it can me used else where..?

Code:

import java.sql.*;

public class File {
       
                public static void main(String s[])
                throws SQLException,Exception{
                Class.forName("com.ibm.db2.jcc.DB2Driver");
                Connection con = DriverManager.getConnection("jdbc:db2:SMART","",""  );
               
               
                String name;
                int id;
                       
                System.out.println("Enter a the id: ");
                       
                System.out.println("\n\nEnter the name: ");
                       
                String query = "insert into db2admin.enduser values (?,?)";
                       
                PreparedStatement ps=con.prepareStatement (query); 
                       
                ps.setInt(1,id);
                ps.setString(2,name);
                int i=ps.executeUpdate();
                System.out.println("record inserted count:"+i);
                con.close();
               
               
               
               
        }

}



All times are GMT +5.5. The time now is 14:55.