Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Getting values in list  RSS feed

 
Mateen Dar
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to popluate a html control with data from a database. this code is not working. whats wrong.


<%@page import="java.sql.*,java.io.*" %>
<%
Connection con;
Statement s;
ResultSet rs;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc dbc:temp","","");
s=con.createStatement();
rs=s.execute( "select node_name from node_info");
}
while(rs.next())
%>
<select name = "source">
<option><%= rs.getString(1) %>

<%
catch(Exception e)
{
System.out.println(e.toString());
}
%>








</body>
</html>
 
Jayesh Lalwani
Ranch Hand
Posts: 502
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your select is not closed, the while loop should have braces, the tr-catch block is not proper, there is no opening html and body tags and probably you need one select for the entire result
Try this


All the Java code with the HTML can make your page unreadable. Usually what I do is first make an HTML page with dummy data, check whether the page works fine without Java code, and then add the Java code to it
 
pankaj patil
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this will work

<%@page import="java.sql.*,java.io.*" %>
<%
Connection con;
Statement s;
ResultSet rs;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc dbc:temp","","");
s=con.createStatement();
rs=s.execute( "select node_name from node_info");
}
%>
<select name = "source">
<%
while(rs.next())
{String temp=rs.getString(1)
%>

<option value="<%= temp%>"><%=temp %>

<%}// end of while
%>
</select>
<%
}// end of try
catch(Exception e)
{
System.out.println(e.toString());
}
%>








</body>
</html>

With Regards
pankaj
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!