alpha_calling
alpha_calling

Reputation: 89

to retrieve data from database and show it with tha radio buttons with radio botton containing the data value

i am building a web based railway ticket reservation system. I want to retrieve all the required data from the database using while loop but show one of the data i.e train_no with radio button so that i could pass it to the next jsp. but while doing this i am getting an sql exception "data not found" . please help me. following is a part of the code...

    <%@page import="java.sql.*"%>
          <%@page import="javax.servlet.*"%>
          <%@page import="java.io.*"%>
        <%String s3=String.valueOf(request.getAttribute("s2"));
        String d3=String.valueOf(request.getAttribute("d2"));
        String dj3=String.valueOf(request.getAttribute("dj2"));

        %>

<%  Connection con;
             PreparedStatement ps,ps1;
             ResultSet rs;
 try{
String driverName="sun.jdbc.odbc.JdbcOdbcDriver";
String url="jdbc:odbc:rail";
        String username="root";
        String password="root";
        Class.forName(driverName);
        con=DriverManager.getConnection(url,username,password);
         ps=con.prepareStatement("Select * from train_for where source=? and destination=? and doj=?");
         ps.setString(1,s3);
         ps.setString(2,d3);
         ps.setString(3,dj3);
         rs=ps.executeQuery();
         while(rs.next())
             { %>
             <tr><td><input type="radio" value="<%=rs.getString("train_no")%>" name="rad1"><%=rs.getString("train_no")%></td></tr>
             <tr><td><%=rs.getString(4)%></td></tr>
             <tr><td><%=rs.getString(5)%></td></tr>
             <br><br>
          <%}
         }
 catch(Exception e)
      {
      out.println(e);
      }
             %>

Upvotes: 0

Views: 5532

Answers (1)

alpha_calling
alpha_calling

Reputation: 89

This worked fine.. :)

while(rs.next())
         {
         String no= rs.getString(1);
         String dt= rs.getString(4);
         String st= rs.getString(5);
         %>

         <input type="radio" name="rad1" value="<%=no%>"/><%=no%>
         <%=dt%>
         <%=st%>
         <br>

      <%}

Upvotes: 1

Related Questions