Fatima Eman Fatima Eman - 4 months ago 22
SQL Question

get value from database table where id = ? java

I have one table
Table name is PARKTABLE

Now I want to get these values in jsp
my code is here

<jsp:useBean id="loginBean" scope="session" class="vustudent.Login" />
<input type="text" name="takei" value='<jsp:getProperty name="loginBean" property="loginid" />' />
String dbId = request.getParameter("takei");
String url= "jdbc:derby://localhost:1527/sample;create=true; user=app; password=app";
Connection con = DriverManager.getConnection(url);
Statement st= con.createStatement();
String query = "SELECT * FROM PARKTABLE WHERE ID =\'"+ dbId + "\' ";
ResultSet rs = st.executeQuery(query);
// iterate through the java resultset
if (rs.next())
String placeOne = rs.getString("Place1");
String placeTwo = rs.getString("Place2");
System.out.println("place1" +placeOne);
System.out.println("place1" +placeTwo);
<input type="text" name="pl1value" value='placeOne' />

it prints placeOne in input text field istead of its value.
I want to print placeOne value red or green from database.
where I am wrong?


Change your input text as below:

<input type="text" name="pl1value" value='<%=placeOne%>' />

And then, change your Java code as below:

String placeOne = "";
String placeTwo = "";

 if (rs.next())
        placeOne = rs.getString("Place1");
        placeTwo = rs.getString("Place2"); 
        System.out.println("place1" +placeOne);
        System.out.println("place1" +placeTwo);

So your input type can print default value even your query return no data.