aspose file tools*
The moose likes JSP and the fly likes error due to accessing database connection using jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "error due to accessing database connection using jsp" Watch "error due to accessing database connection using jsp" New topic
Author

error due to accessing database connection using jsp

raji navaneethan
Greenhorn

Joined: Apr 06, 2006
Posts: 15
Hi,

I have an error, during accessing a datbase using jsp:useBean from jsp.Urgent i need this one


my source code ispackage SQLBean;

DbBean.java

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

public class DbBean implements java.io.Serializable{

private String dbDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
private Connection dbCon;

public DbBean(){
super();
}

public boolean connect() throws ClassNotFoundException,SQLException{
Class.forName(dbDriver);
dbCon = DriverManager.getConnection("jdbc dbc:mybean","","");
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;
}

}


database.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="*" />

<center>
<h2> Results from </h2>
<hr>
<br><br>
<table>

<%
db.connect();


ResultSet rs = db.execSQL("select * from employ");
int i = db.updateSQL("UPDATE employ set fname = 'hello world' where empno='000010'");
out.println(i);



%>

<%
while(rs.next()) {
%>
<%= rs.getString("empno") %>
<BR>
<%
}
%>
<BR>
<%

db.close();

%>

Done

</table>

</body>

</HTML>


The error like this

org.apache.jasper.JasperException: Unable to compile class for JSPNote: sun.tools.javac.Main has been deprecated.
error: Invalid class file format in C:\Program Files\Apache Tomcat 4.0\webapps\muthu\WEB-INF\classes\SQLBean\DbBean.class. The major.minor version '49.0' is too recent for this tool to understand.


An error occurred at line: 7 in the jsp file: /database.jsp

Generated servlet error:
C:\Program Files\Apache Tomcat 4.0\work\localhost\muthu\database$jsp.java:65: Class SQLBean.DbBean not found.
SQLBean.DbBean db = null;
^


An error occurred at line: 7 in the jsp file: /database.jsp

Generated servlet error:
C:\Program Files\Apache Tomcat 4.0\work\localhost\muthu\database$jsp.java:68: Class SQLBean.DbBean not found.
db= (SQLBean.DbBean)
^


An error occurred at line: 7 in the jsp file: /database.jsp

Generated servlet error:
C:\Program Files\Apache Tomcat 4.0\work\localhost\muthu\database$jsp.java:73: Class SQLBean.DbBean not found.
db = (SQLBean.DbBean) java.beans.Beans.instantiate(this.getClass().getClassLoader(), "SQLBean.DbBean");
^
4 errors, 1 warning

Anybody help me?
Thanx in advance
jayanandan thiagarajan
Greenhorn

Joined: Apr 27, 2006
Posts: 21
You'll need to put your bean in it's own package, and import it using
<%@page import="mybeanpackage.*"%>

This is so because since JDK.1.4, you can no longer import classes that are
not in a package.

(Actually i am getting this result from http://www.codecomments.com/archive251-2004-4-183596.html for yoursake only)

Try it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: error due to accessing database connection using jsp