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