I am currently trying to read from a database and output the information to an html file. But I am having trouble reading from the database. Surely it is because of my lack of knowledge of java and database programming.
I am having no trouble connecting to the database and creating my query string. My query string is created from a series of checkboxes, so it is not the same every time. It also may contain strings and integers. That is where I feel my problem is. Since my query string is not the same everytime I don't know how to successfully output my data. When I execute my query is when I am having the problems. Here is a bit of my code.
public String getData( String query, StringBuffer back)
{
String query = query;
ResultSet rs = null;
try
{
rs = st.executeQuery(query);
back.append( "<table border=\10\" >\n" );
while(rs.next())
{
back.append( "<tr><td>" + rs.getString(1) + "</td></tr>");
}
back.append( "</table>" );
}
catch( SQLException e )
{
back.append( "<h6>something bad is happening</h6>");
e.printStackTrace();
return null;
}
return new String( back );
}
Any help would be great!