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 5 of 5

Thread: get value from database by searching

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

    Default get value from database by searching

    Hi. Sorry if such a question was asked before. I am coding an application for entering child patient details as registration. The basic details were entered in a previous form. Now i am adding the diagnosis. here i have a problem. i require that when i type the id into a text box and press search another textbox should return the associated name. i got code for it but it doesn't work here is the code i used
    try{
                Class.forName("com.mysql.jdbc.Driver");
                Connection conn =  DriverManager.getConnection(
                         "jdbc:mysql://localhost/autmgt","root","pass");
     
                Statement st = conn.createStatement();
             ResultSet rs=null;   
     
            String pval1=text1.getText();
            String SQL="select * from child where CID="+"'"+pval1+"'";
            rs=st.executeQuery(SQL);
            String k=rs.getString("CName");
            text2.setText(k);
     
     
     
     
     
     }catch(Exception e){}

    TIA
    Last edited by Light Mike; August 23rd, 2012 at 02:03 AM.


  2. #2
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 139 Times in 134 Posts

    Default Re: get value from database by searching

    "but it doesn't work" doesn't give us much to go on. What problems are you having? Are you getting error messages? Is your program not behaving well? Also consider fixing your code indentation and make it more uniform, usually 3 spaces suffices plenty. It's hard enough trying to figure out someone else's code that you really don't want to make it harder for us by posting poorly formatted code.

    Luck!

  3. #3
    Junior Member
    Join Date
    Aug 2012
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: get value from database by searching

    sorry for that. no i dont get any errors. when i type say 123(which should return bob) and press search, nothing happens.

  4. #4
    Junior Member
    Join Date
    Aug 2012
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: get value from database by searching

    anyone??? i really need help on this.

  5. #5
    Junior Member
    Join Date
    Aug 2012
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: get value from database by searching

    ok solved it was a syntax error here is the code i used
    try{
                Class.forName("com.mysql.jdbc.Driver");
                Connection conn =  DriverManager.getConnection(
                         "jdbc:mysql://localhost/autmgt","root","K13nn0r");
                      Statement st = conn.createStatement();
             ResultSet rs=null;   
     
            String pval1=text1.getText();
            String SQL="select * from child where CID='"+pval1+"'";
            rs=st.executeQuery(SQL);
           // String k=rs.getString(2);
            while(rs.next()){
                text2.setText(rs.getString("CName"));
            }
    }catch(Exception e){}

Similar Threads

  1. Searching
    By killer3p0 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: May 17th, 2012, 08:06 AM
  2. [SOLVED] Searching issues.
    By Saintroi in forum What's Wrong With My Code?
    Replies: 2
    Last Post: April 28th, 2012, 07:26 PM
  3. how to searching data from database using servlet??
    By mr.nash in forum Java ME (Mobile Edition)
    Replies: 1
    Last Post: December 21st, 2011, 02:09 PM
  4. searching a string
    By dvsumosize in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 23rd, 2010, 12:31 AM
  5. Searching Data
    By kalees in forum JavaServer Pages: JSP & JSTL
    Replies: 3
    Last Post: October 2nd, 2009, 03:23 AM