1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

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