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

Thread: SELECT statements Java

  1. #1
    Junior Member
    Join Date
    Jul 2018
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default SELECT statements Java

    Hi all.
    I am trying to view certain date (that has been chosen by user input) and display it on the screen.
    The idea of this Select statement is that it should displayed all room number and dates it has been booked for.

    So if the user inputs room CG123 it should display all the dates (start and end) it has been book for.
    I need help trying to display the results.

    Code:
    System.out.println("View Booked Room\n");
     
                        System.out.println("Enter Room Number:");
                        String roomava = s.next();
     
                         try {
     
                            String sql2 = "SELECT ROOMNUMBER, STARTDATE, ENDDATE FROM "
                                          + "BOOKINGS WHERE ROOMNUMBER=?";
                            PreparedStatement ps2 = conn.prepareStatement(sql2);
     
                            ps2.setString(1, roomava);
                            ps2.executeQuery();
     
                        } catch (Exception e) {
                            System.err.println("Error. Please check input entry and date format");
                        }
     
                        break;
    Last edited by Veej10; July 27th, 2018 at 09:54 AM. Reason: changed code and question

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,559
    Thanks
    52
    Thanked 2,317 Times in 2,273 Posts

    Default Re: SELECT statements Java

    It comes with an error
    Please copy the full text of the error message and paste it here. It has important info about the error.

    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Jul 2018
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: SELECT statements Java

    the error was the catch exception because i had no output.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,559
    Thanks
    52
    Thanked 2,317 Times in 2,273 Posts

    Default Re: SELECT statements Java

    Can you copy the full text of the error message and paste it here?

    Be sure to add a call to the printStackTrace() method to the catch block to show the full error message.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Replies: 0
    Last Post: May 14th, 2014, 01:52 AM
  2. Replies: 1
    Last Post: May 1st, 2014, 03:55 AM
  3. Questions about if statements and if-else statements
    By chakana101 in forum Java Theory & Questions
    Replies: 5
    Last Post: March 23rd, 2014, 06:37 PM
  4. Replies: 1
    Last Post: January 27th, 2014, 12:46 AM
  5. Im very new to java And switch statements
    By RevChe in forum Loops & Control Statements
    Replies: 9
    Last Post: March 17th, 2013, 11:14 AM

Tags for this Thread