evergreean43
Technical User
I am trying to get my first database bean working in my Tomcat 5.5 Container.
The page keeps giving me null output. I know it has a value in the MySql database but it keeps showing null in my JSP with JDBC bean.
Please advise what I am doing wrong as I assume my problem is in the JSP where I am calling the bean:
Here is my Java class file:
The page keeps giving me null output. I know it has a value in the MySql database but it keeps showing null in my JSP with JDBC bean.
Please advise what I am doing wrong as I assume my problem is in the JSP where I am calling the bean:
Code:
<%@ page import = "num.dbBean" %>
<jsp:useBean id="db" scope="session" class="num.dbBean">
<jsp:setProperty name="db" property="resultTable" />
</jsp:useBean>
<html>
<body>
s
<jsp:getProperty name="db" property="resultTable" />
</body>
</html>
Here is my Java class file:
Code:
package num;
import java.io.*;
import java.sql.*;
import java.util.*;
public class dbBean implements Serializable
{
protected transient String query;
protected transient String resultTable;
protected transient Connection conn;
public dbBean()
{
//query = null;
resultTable = null;
conn = null;
}
public void setResultTable(String resultTable)
{
this.resultTable = resultTable;
}
public String getResultTable()
{
this.viewDatabaseTable();
return resultTable;
}
public void viewDatabaseTable()
{
executeQueryr(query);
}
public void executeQueryr(String query)
{
if(conn == null)
{
initializeDb();
}
try
{
Statement stmt = conn.createStatement();
ResultSet results = stmt.executeQuery("SELECT * from user where lastname = 'Jones'");
while(results.next())
{
//results.getString("lastname");
String lastName = results.getString("lastname");
System.out.println(lastName);
}
stmt.close();
results.close();
conn.close();
}
catch (SQLException sqle)
{
sqle.printStackTrace();
}
}
public void initializeDb()
{
try
{
Class.forName("org.gjt.mm.mysql.Driver");
conn = DriverManager.getConnection("jdbc:mysql://localhost/myfirst?user=root&password=mypasswordhere");
}
catch (SQLException sqle)
{
sqle.printStackTrace();
}
catch (ClassNotFoundException cnfe)
{
cnfe.printStackTrace();
}
}
}