Need help with passing user defined variable in SQLJ

Discussion in 'Database' started by redkryptonite, Mar 7, 2012.

  1. redkryptonite

    redkryptonite New Member

    Joined:
    Mar 7, 2012
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    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();
    		
    		
    		
    		
    	}
    
    }
     
    Last edited by a moderator: Mar 7, 2012

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice