<h3><m:student>Joe Jones</m:student></h3> <hr />
(EVAL_BODY_INCLUDE) - The Students information is Joe Jones
package mytags;
import javax.servlet.*;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
import java.util.*;
import java.sql.*;
public class GetStudent extends BodyTagSupport {
private String name;
private JspWriter out;
static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
static final String DB_URL = "jdbc:mysql://localhost/cs4010";
static final String USER = "cs4010";
static final String PASS = "cs4010";
public int doStartTag() throws JspException {
out=pageContext.getOut();
try {
out.print("(<font color='BLUE'>EVAL_BODY_INCLUDE</font>) - The Students information is ");
} catch (Exception e) {
e.printStackTrace();
}
return EVAL_BODY_INCLUDE;
}
// TheStudent() is not called
public String TheStudent(String who){
Connection conn = null;
Statement stmt = null;
String theReturn="";
try {
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection(DB_URL,USER,PASS);
stmt = conn.createStatement();
String this_query="SELECT name, year, test FROM student where name=\"";
this_query=this_query+who+"\";";
ResultSet rs = stmt.executeQuery(this_query);
while (rs.next()) {
String the_name = rs.getString("name");
String the_year = rs.getString("year");
int the_grade = rs.getInt("test");
theReturn="Name: " + the_name + " Year: "+the_year+" Grade: "+the_grade;
}
rs.close();
stmt.close();
conn.close();
} catch (Exception e) {
e.printStackTrace();
}
return theReturn;
}
}