I have been having a fun time with a project I am working on. I'm looking at passing a var from the URL to the JSP taking that var and using it in a query to the database, taking the result set back to the jsp to display on the site. However I cannot seem to get the resultset back to the jsp. Not sure I am even doing this correctly.

How does this look?

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;

import java.sql.*;

public class SomeClass implements java.io.Serializable {

private int someid=5;
private String var1 ="";
private String var2 ="";

public Category() {}

public void setRequest(HttpServletRequest req) {

Connection conn= null;
try
{
Class.forvar1("org.gjt.mm.mysql.Driver");
conn= DriverManager.getConnection("jdbc:mysql://localhost:3306/db", "user", "pass");
}
catch (ClassNotFoundException e2)
{
// TODO Auto-generated catch block
e2.printStackTrace();
}
catch (SQLException e1)
{
// TODO Auto-generated catch block
e1.printStackTrace();
}
synchronized(conn)
{
try
{
Statement statement = conn.createStatement();
ResultSet rs = statement.executeQuery("SELECT var1,var2 FROM table WHERE someid='"+someid+"'");
setVar1(rs.getString("var1"));
setVar2(rs.getString("var2"));
if (rs !=null) rs.close();
if (conn!=null) conn.close();
if (statement !=null) statement.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}
}

public void setvar1(String var1) {
this.var1 = var1;
}

public String getvar1(){
return var1;
}

public void setvar2(String var2) {
this.var2 = var2;
}

public String getvar2(){
return var2;
}
}



JSP
<jsp:useBean id="Some" class="com.fh.db.SomeClass" scope="page" />
<%=Same.getVar1()%>
<%=Same.getVar2()%>

or <%=var%>

or <%=rs.VAR1%>