Hi,
I have problem by using useBean in JSP,the error is
Error: 500
Internal Servlet Error:
javax.servlet.ServletException: Cannot create bean of
class AiirDatabaseQuery at
rg.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:367)
at
_0005cbeantest_0002ejspbeantest_jsp_1._jspService(_0005cbeantest_0002ejspbeantest_jsp_1.java:106)
at
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:130)
at
javax.servlet.http.HttpServlet.service(HttpServlet.java:868)
at
org.apache.jasper.runtime.JspServlet$JspServletWrapper.service(JspServlet.java:159)
at
org.apache.jasper.runtime.JspServlet.serviceJspFile(JspServlet.java:243)
at
org.apache.jasper.runtime.JspServlet.service(JspServlet.java:348)
at
javax.servlet.http.HttpServlet.service(HttpServlet.java:868)
at
org.apache.tomcat.core.ServiceInvocationHandler.method(ServletWrapper.java:621)
at
org.apache.tomcat.core.ServletWrapper.handleInvocation(ServletWrapper.java:529)
at
org.apache.tomcat.core.ServletWrapper.handleRequest(ServletWrapper.java:373)
at
org.apache.tomcat.core.Context.handleRequest(Context.java:648)
at
org.apache.tomcat.server.ConnectionHandler.run(ConnectionHandler.java:205)
Actual code is:
---------------
This is the JSP page
<html>
<HEAD>
<TITLE>All India Internet Radio</TITLE>
</HEAD>
<body>
<%! int custid=0; %>
<jsp:useBean id="dbquery"
class="AiirDatabaseQuery" type="AiirDatabaseQuery" />
<ul>
<li>custid:<%=dbquery.getCustIdByEmailId("[EMAIL PROTECTED]")
%>
</ul>
</body>
</html>
and the class file code(AiirDatabaseQuery)
------------------------------------------
import java.io.*;import java.text.*;import
java.util.*;import java.util.Date;
import java.sql.*;import javax.sql.*;public class
AiirDatabaseQuery {
Connection dbConnection;AiirDatabaseQuery(){ try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection dbConnection=
DriverManager.getConnection("jdbc:odbc:aidbora","aidb","aidb");
System.out.println("Connection has been
established");
}catch (ClassNotFoundException cnfe){
System.err.println("Class not found exception." );
cnfe.printStackTrace();
} catch (Exception ex) {
System.err.println("Caught an exception."
);
ex.printStackTrace();}}
public int insertCustomer(int customerid, String
firstName, String
lastName,String sex,String age,String income,String
profession,String
education,String familysize,String country,String
company,String jobtitle,String
officemailaddress,String officemailaddress1,String
officecity,String
officestate,String officeZip,String
officeAreacode,String officephoneno,String
officefax,String officeEmailaddress,String
Homemailaddress,String
Homemailaddress1,String Homecity,String
Homestate,String HomeZip,String
HomeAreacode,String Homephoneno,String Homefax,String
HomeEmailaddress,String
personalhomepage,String noofvisits,String
lastvisit,String ipaddress,String
browser,java.util.Date dateofregistration,int
emailsent,String inactivate,String
load,java.util.Date dateloaded,String birthyear){ int
id=customerid;try{
java.sql.Date sqlDateOfReg= new
java.sql.Date(dateofregistration.getTime());
java.sql.Date sqlDateLoaded= new
java.sql.Date(dateloaded.getTime());
String insertStatement =
"insert into customers values ( ? , ?
, ? , ?, ?, ?, ?, ?, ?, ?,
?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
?, ?, ?, ?, ?, ?, ?, ?, ?,
?, ?, ?, ?)"; PreparedStatement prepStmt =
dbConnection.prepareStatement(insertStatement);
prepStmt.setInt(1, customerid);
prepStmt.setString(2, firstName);
prepStmt.setString(3, lastName);
prepStmt.setString(4,sex);
prepStmt.setString(5,age);
prepStmt.setString(6,income);
prepStmt.setString(7,profession);
prepStmt.setString(8,education);
prepStmt.setString(9,familysize);
prepStmt.setString(10,country);
prepStmt.setString(11,company);
prepStmt.setString(12,jobtitle);
prepStmt.setString(13,officemailaddress);
prepStmt.setString(14,officemailaddress1);
prepStmt.setString(15,officecity);
prepStmt.setString(16,officestate);
prepStmt.setString(17,officeZip);
prepStmt.setString(18,officeAreacode);
prepStmt.setString(19,officephoneno);
prepStmt.setString(20,officefax);
prepStmt.setString(21,officeEmailaddress);
prepStmt.setString(22,Homemailaddress);
prepStmt.setString(23,Homemailaddress1);
prepStmt.setString(24,Homecity);
prepStmt.setString(25,Homestate);
prepStmt.setString(26,HomeZip);
prepStmt.setString(27,HomeAreacode);
prepStmt.setString(28,Homephoneno);
prepStmt.setString(29,Homefax);
prepStmt.setString(30,HomeEmailaddress);
prepStmt.setString(31,personalhomepage);
prepStmt.setString(32,noofvisits);
prepStmt.setString(33,lastvisit);
prepStmt.setString(34,ipaddress);
prepStmt.setString(35,browser);
prepStmt.setDate(36,sqlDateOfReg);
prepStmt.setInt(37,emailsent);
prepStmt.setString(38,inactivate);
prepStmt.setString(39,load);
prepStmt.setDate(40,sqlDateLoaded);
prepStmt.setString(41, birthyear);
prepStmt.executeUpdate();
prepStmt.close(); }catch (SQLException
sqle){
System.err.println("SQL exception." );
sqle.printStackTrace(); return 0; }
return id; }public int getCustIdByEmailId(String
emailAddress){ int id=0;
try{ String theStatement1=
"SELECT customerid from customers where
homeemailaddress= ?";
PreparedStatement queryStat1=
dbConnection.prepareStatement(theStatement1);
queryStat1.setString(1,emailAddress);
ResultSet result1= queryStat1.executeQuery();
//queryStat.setString(2,emailAddress);
if(result1.next()){
id= result1.getInt(1); queryStat1.close();
}else{ String theStatement2=
"SELECT customerid from customers where
officeemailaddress= ?";
PreparedStatement queryStat2=
dbConnection.prepareStatement(theStatement2);
queryStat2.setString(1,emailAddress);
ResultSet result2=
queryStat2.executeQuery();
if(result2.next()){
id= result2.getInt(1);
}else id= 0;
queryStat2.close(); }
}catch (SQLException sqle){ System.err.println("SQL
exception." );
sqle.printStackTrace(); } return id; }
Pls go through this.I would appreciate you if you can
find the error and anybody can sugessest the solution.
Waiting for reply....
Satya
__________________________________________________
Do You Yahoo!?
Talk to your friends online with Yahoo! Messenger.
http://im.yahoo.com
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets