hello everyone
please help!!
i have tried a lot to do everything but couldn't succeed in calling data values from beans class which is calling the values from database
whole code of ConnectionBean.java and conference.jsp is attached.
please please anybody help me in running this code
the error that usually comes is "cannot create bean of ConnectionBean class"
and the root cause is "cannot find connection bean class"
i want to tell that i have
tomcat server and the path for both .java and .jsp is as follows:
d:\jakarta-tomcat-4.0-b5\webapps\examples\web-inf\classes\babaji\ch_7\ConnectionBean.java
d:\jakarta-tomcat-4.0-b5\webapps\examples\jsp\conference.jsp
//conference.jsp starts from here
<%@ page import="java.sql.*,babaji.ch_7.*"%>
<
jsp:useBean id="connection" class="ConnectionBean" scope="session"/>
<html>
<body>
<center>
<font size="+2" face="arial" ><b>Conference Registration</b></font>
<form action="shuttle.jsp" method="post">
<table border="1" bgcolor="tan" width="50%" align="center">
<tr><td><table border="0" bgcolor="white" cellspacing="0" width="100%">
<tr bgcolor="tan">
<th> </th><th>City</th><th>Tickets Remaining</th></tr>
<%
String sql = "select * from conferences";
ResultSet results = connection.executeQuery(sql);
while(results.next())
{
if(results.getInt("seats") > 0)
{
%>
<td>
<input type="radio" name="show" value="<%= results.getString("ID") %>"</td>
</td>
<%
}
%>
<td><%= results.getString("city") %> </td>
<td align="center"><%= results.getString("seats") %>
</td>
</tr>
<%
}
%>
</table>
</td></tr></table>
<p>
<input type="submit" value="Next Generation (choose shuttle)">
</form>
</center>
</body>
</html>
//conference.jsp ends here
//ConnectionBean.java starts from here
package babaji.ch_7;
import java.sql.*;
import javax.servlet.http.*;
public class ConnectionBean implements HttpSessionBindingListener
{
private Connection con;
private Statement stat;
private static final String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
private static final String dbURL = "jdbc
dbc
roject4";
public ConnectionBean()
{
try
{
Class.forName(driver);
con = DriverManager.getConnection(dbURL);
stat = con.createStatement();
}
catch(ClassNotFoundException e)
{}
catch(SQLException e)
{}
}
public void commit() throws SQLException
{
con.commit();
}
public void rollback() throws SQLException
{
con.rollback();
}
public void setAutoCommit(boolean autoCommit) throws SQLException
{
con.setAutoCommit(autoCommit);
}
public ResultSet executeQuery(String sql) throws SQLException
{
return stat.executeQuery(sql);
}
public int executeUpdate(String sql) throws SQLException
{
return stat.executeUpdate(sql);
}
public void valueBound(HttpSessionBindingEvent event)
{
System.err.println("ConnectionBean: in the valueBound method");
try
{
if(con == null || con.isClosed())
{
con = DriverManager.getConnection(dbURL);
stat = con.createStatement();
}
}
catch(SQLException e)
{
con = null;
}
}
public void valueUnbound(HttpSessionBindingEvent event)
{
try
{
con.close();
}
catch(SQLException e)
{}
finally
{
con = null;
}
}
protected void finalize()
{
try
{
con.close();
}
catch(SQLException e)
{}
}
}
//ConnectionBean.java ends here
please everybody, i am anxiously waiting for the positive reply; as i have heard a lot about goodness of
java ranch, so referring here today for the first time
i am
scjp certified and want to take scwcd exam soon
ok take care
bye
from Shehzad Khan