0

I tried getting the text into a string variable using the getText() method and then using that string variable in the preparedStatement of JDBC. The application runs without any hiccups but gives a blank output.

     Connection conn;

     try{
         conn = DriverManager.getConnection(CONN_STRING,USERNAME,PASSWORD);

         PreparedStatement pstmt=conn.prepareStatement("SELECT * FROM airplane.airlinedb WHERE 
         ORIGIN = ? AND DESTINATION = ? LIMIT 100;");
         pstmt.setString(1,j.from); // from is the string variable
         pstmt.setString(2,j.destination); //destination is another string variable
         ResultSet rs=pstmt.executeQuery();  
         User user;
         while(rs.next())
         {
             user = new User(rs.getString("ORIGIN"), 
             rs.getString("DESTINATION"),rs.getInt("FLIGHT_NUMBER"), rs.getInt("TIME_TRAVEL") , 
             rs.getInt("PRICE"));
             usersList.add(user);
         }
         conn.close();


        }
         catch(SQLException e){
         System.err.println(e);
         }
     return usersList;
}

Please do let me know if u need any additional info P.S:- this is my first java application so have been thru a lot of hiccups this is the front end of the application.. i am trying to get the text from source and destiantion text field and use that into the different queries for the different options .. Front End adding the screenshot of the blank outputFinal Output

  • 1
    "this is my first java application" - in that case I'd strongly suggest to work on individual problems first, i.e. get a firm grasp of the language and then dive into _either_ JDBC _or_ UI development. You're trying to do it all at once and that's a way to get into trouble really quick. – Thomas Oct 16 '19 at 14:14
  • check-out this link: https://www.geeksforgeeks.org/java-swing-jtextfield/ . If you understand this, hopefully your problem will be solved. Otherwise please learn basic components of java and then dive into UI/JDBC. – MD Ruhul Amin Oct 16 '19 at 14:17
  • Please note that it's hard to tell what's going wrong in your code because there's a lot of information missing, e.g. how and when you get the data from the textfields, whether the query could actually return anything based on that data (because we neither know the table layout nor its data) etc. - I assume you didn't get any ouput from `System.err.println(e);`, did you? If you did then you need to post that. Otherwise please elaborate on "gives a blank output" - ho do you determine that? And did you already step through your application with a debugger? – Thomas Oct 16 '19 at 14:18
  • hey i have added the screenshots of the front end and blank screenshot i have been talking about please do help .thnx @Thomas – Amit Patil Oct 16 '19 at 15:24
  • We don't need screenshots, we need code. From the screenshots I can only tell that it could be anything, from the wrong elements being queried over no data being available to the returned list not being handled correctly. Did you check the parameters you're putting into the query for correctnes? Did you check the table content? Did you check the content of `usersList` before returning it? (All that can be done with a debugger or at least some simple log statements) – Thomas Oct 16 '19 at 15:34

0 Answers0