Results 1 to 10 of 10

Thread: Help In JDBC

  1. #1
    juhiswt is offline Member
    Join Date
    Mar 2011
    Posts
    30
    Rep Power
    0

    Default Help In JDBC

    I am making a program to search the student detail by enterering the roll number.In this I want to do if the student of entered roll number doest not exist in databse then it should diaplay a dialogue box The student of that roll number does not exist.
    I have used
    if(rs.wasNull())
    display the dialogue box
    else
    display the details
    but in each case else is executing but if is not why it is?

  2. #2
    Bigfatcat is offline Member
    Join Date
    Apr 2011
    Location
    UK
    Posts
    10
    Rep Power
    0

    Default

    Could you post the code relating to the assignment of the rs (ResultSet I assume)?

    No need for the whole code block, just the bits relating to 'rs'.

  3. #3
    juhiswt is offline Member
    Join Date
    Mar 2011
    Posts
    30
    Rep Power
    0

    Default

    Yes its result set

  4. #4
    juhiswt is offline Member
    Join Date
    Mar 2011
    Posts
    30
    Rep Power
    0

    Default

    while(res.next())
    {
    String name=res.getString(1);
    String city=res.getString(2);
    String class1=res.getString(3);
    if(res.wasNull())
    {

    tf1.setText("Does nOt EXist");
    tf2.setText("Does nOt EXist");
    tf3.setText("Does nOt EXist");
    }
    else
    {
    tf1.setText(name);
    tf2.setText(city);
    tf3.setText(class1);
    }

    }

  5. #5
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,732
    Blog Entries
    7
    Rep Power
    21

    Default

    Read the API documentation for the ResultSet.wasNull() method; it doesn't do what you hope it does; hint, if there is no ResultSet.next() element no student matched the criteria ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  6. #6
    juhiswt is offline Member
    Join Date
    Mar 2011
    Posts
    30
    Rep Power
    0

    Default

    @JosAH could u please tell me what should i use and i have read wasNull method but i can not get its use could u please tell me this also..
    Thanx

  7. #7
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,732
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by juhiswt View Post
    @JosAH could u please tell me what should i use and i have read wasNull method but i can not get its use could u please tell me this also..
    Thanx
    If no row exists in the database for the given sql query, there doesn't exist a ResultSet.next() (i.e. that method returns false after the first call) so your while loop body is never entered; you should display your notification in that case.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  8. #8
    juhiswt is offline Member
    Join Date
    Mar 2011
    Posts
    30
    Rep Power
    0

    Default

    @JosAH thanx alot ...

  9. #9
    RichersooN is offline Senior Member
    Join Date
    Jan 2011
    Location
    Rizal Province, Philippiines
    Posts
    167
    Rep Power
    0

    Default

    I think your problem is quite similar to my problem:

    http://www.java-forums.org/database/...return-same-i-
    need-refresh.html

    There is bug on resultset

  10. #10
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,732
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by RichersooN View Post
    I think your problem is quite similar to my problem:

    http://www.java-forums.org/database/...return-same-i-
    need-refresh.html

    There is bug on resultset
    Have you read this thread? What the OP described most certainly wasn't a bug on the ResultSet part. b.t.w. the bugbase is full of bugs that aren't bugs ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. swt with Jdbc
    By english in forum SWT / JFace
    Replies: 0
    Last Post: 03-11-2011, 01:12 PM
  2. Jdbc
    By KumbhaniMehul in forum Java Servlet
    Replies: 1
    Last Post: 04-06-2010, 07:18 PM
  3. Replies: 0
    Last Post: 04-01-2008, 11:17 AM
  4. Jdbc
    By siwa in forum JDBC
    Replies: 4
    Last Post: 11-09-2007, 08:31 AM
  5. Replies: 0
    Last Post: 09-28-2007, 01:56 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •