Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Need help with passing user defined variable in SQLJ

  1. #1
    Junior Member
    Join Date
    Mar 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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..?

    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();




    }

    }


  2. #2
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: Need help with passing user defined variable in SQLJ

    Go through the Scanner or InputStreamReader for reading values from the user.
    Loop through the ResultSet and store values either in some data structure or a single variable.

Similar Threads

  1. [SOLVED] Printing an ArrayList of user-defined Objects
    By er1111 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 2nd, 2012, 11:06 AM
  2. Replies: 7
    Last Post: October 7th, 2011, 11:38 AM
  3. User-Defined Methods
    By ZippyShannon in forum What's Wrong With My Code?
    Replies: 4
    Last Post: July 28th, 2011, 10:23 PM
  4. Allowing user to input variable.
    By That1guy in forum What's Wrong With My Code?
    Replies: 5
    Last Post: November 15th, 2010, 11:30 PM
  5. User Defined Methods
    By mgutierrez19 in forum Object Oriented Programming
    Replies: 11
    Last Post: October 20th, 2009, 06:57 PM