• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Error in JSP when using bean concept

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
// My JSP coding. This is stored in the following path ]http://localhost:8080/vennila/test.jsp
<HTML>
<HEAD><TITLE>DataBase Search</TITLE></HEAD>
<BODY>

<%@ page language="Java" import="java.sql.*" %>
<jsp:useBean id="db" scope="application" class="SQLBean.DbBean"/>
<jsp:setProperty name="db" property="*" />

<%!
ResultSet rs = null ;
ResultSetMetaData rsmd = null ;
int numColumns ;
int i;
%>
<center>
<h2> Results from </h2>
<hr>
<br><br>
<table>
<%
db.connect();
rs = db.execSQL("select * from emp1");
i = db.updateSQL("UPDATE emp1 set fname = 'hello world' where
empid=101");
out.println(i);

rsmd = rs.getMetaData();
numColumns = rsmd.getColumnCount();
for(int column=1; column <= numColumns; column++)
{
out.println(rsmd.getColumnName(column));
}
%>

<%
while(rs.next())
{
%>
<%= rs.getString("empid") %>
<BR>
<%
}
%>
<BR>
<%
db.close();
%>
Done
</table>
</body>
</HTML>



//My Java Package Coding. It is compiled and stored in the following path :
C:\Program Files\Apache Tomcat 4.0\webapps\vennila\WEB-INF\classes\



package SQLBean;

import java.sql.*;
import java.io.*;


public class DbBean {

String dbURL = "sun.jdbc.odbc.JdbcOdbcDriver";
String dbDriver = "'jdbc dbc:emp','',''";
private Connection dbCon;

public DbBean(){
super();
}

public boolean connect() throws ClassNotFoundException,SQLException{
Class.forName(dbDriver);
dbCon = DriverManager.getConnection(dbURL);
return true;
}



public void close() throws SQLException{
dbCon.close();
}

public ResultSet execSQL(String sql) throws SQLException{

Statement s = dbCon.createStatement();
ResultSet r = s.executeQuery(sql);
return (r == null) ? null : r;
}



public int updateSQL(String sql) throws SQLException{
Statement s = dbCon.createStatement();
int r = s.executeUpdate(sql);
return (r == 0) ? 0 : r;
}

}

----------------- xxxx-------------------------

When i run the jsp in internet explorer its giving me the following error :

C:\Program Files\Apache Tomcat 4.0 work\localhost\vennila\test$jsp.java:72: Class SQLBean.DbBean not found.
SQLBean.DbBean db = null;
^



I am breaking my head towards this problem for the past 4 days. I am new to Bean concept. kindly help me to solve this problem.

[ April 16, 2006: Message edited by: raji navaneethan ]
[ April 16, 2006: Message edited by: raji navaneethan ]
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

C:\Program Files\Apache Tomcat 4.0\webapps\vennila\WEB-INF\classes\



Should be in C:\Program Files\Apache Tomcat 4.0\webapps\vennila\WEB-INF\classes\SQLBean\
 
raji navaneethan
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
// My JSP coding. This is stored in the following path ]http://localhost:8080/vennila/test.jsp

<HTML>
<HEAD><TITLE>DataBase Search</TITLE></HEAD>
<BODY>

<%@ page language="Java" import="java.sql.*" %>
<jsp:useBean id="db" scope="application" class="SQLBean.DbBean"/>
<jsp:setProperty name="db" property="*" />

<%!
ResultSet rs = null ;
ResultSetMetaData rsmd = null ;
int numColumns ;
int i;
%>
<center>
<h2> Results from </h2>
<hr>
<br><br>
<table>
<%
db.connect();
rs = db.execSQL("select * from emp1");
i = db.updateSQL("UPDATE emp1 set fname = 'hello world' where
empid=101");
out.println(i);

rsmd = rs.getMetaData();
numColumns = rsmd.getColumnCount();
for(int column=1; column <= numColumns; column++)
{
out.println(rsmd.getColumnName(column));
}
%>

<%
while(rs.next())
{
%>
<%= rs.getString("empid") %>
<BR>
<%
}
%>
<BR>
<%
db.close();
%>
Done
</table>
</body>
</HTML>



//My Java Package Coding. It is compiled and stored in the following path: C:\Program Files\Apache Tomcat 4.0\webapps\vennila\WEB-INF\classes\

package SQLBean;

import java.sql.*;
import java.io.*;


public class DbBean {

String dbURL = "sun.jdbc.odbc.JdbcOdbcDriver";
String dbDriver = "'jdbc dbc:emp','',''";
private Connection dbCon;

public DbBean(){
super();
}

public boolean connect() throws ClassNotFoundException,SQLException{
Class.forName(dbDriver);
dbCon = DriverManager.getConnection(dbURL);
return true;
}



public void close() throws SQLException{
dbCon.close();
}

public ResultSet execSQL(String sql) throws SQLException{

Statement s = dbCon.createStatement();
ResultSet r = s.executeQuery(sql);
return (r == null) ? null : r;
}



public int updateSQL(String sql) throws SQLException{
Statement s = dbCon.createStatement();
int r = s.executeUpdate(sql);
return (r == 0) ? 0 : r;
}

}

----------------- xxxx-------------------------

When i run the jsp in internet explorer its giving me the following error :

C:\Program Files\Apache Tomcat 4.0 work\localhost\vennila\test$jsp.java:72: Class SQLBean.DbBean not found.
SQLBean.DbBean db = null;
^


My Java file is stored in the following path : C:\Program Files\Apache Tomcat 4.0\webapps\vennila\WEB-INF\classes

My Class file is stored in the following path :
C:\Program Files\Apache Tomcat 4.0\webapps\vennila\WEB-INF\classes\SQLBean


I am breaking my head towards this problem for the past 4 days. I am new to Bean concept. kindly help me to solve this problem.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't know if it has some relation but try to rename your package in lowercase :
sqlbean, not SQLBean.

Correct your java and jsp files, recompile and redeploy.
 
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
P.S. Never under-estimate naming conventions. They can show you worst.
 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you need to import your SQLBean package in the JSP file, try this :


 
Wink, wink, nudge, nudge, say no more, it's a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic