主题:[讨论]javabean连接mysql的问题
小弟新手,遍了一个JAVABEAN连接MYSQL的代码,不知道那里有问题,麻烦大哥大姐帮忙看看,代码有点长,十分感谢那些耐心看完帖子并给出回复的人....
JAVABEAN的包如下
package opendb;
import java.sql.*;
public class opendb
{
String dbdriver="org.gjt.mm.mysql.driver";
String url="jdbc:mysql:/localhost/staffinfo";
String user="root";
String password="Lee_0593";
Connection conn=null;
ResultSet rs=null;
Statement stmt;
public opendb()
{
try{
Class.forName(dbdriver);
conn= DriverManager.getConnection(url,user,password);
stmt=conn.createStatement();
}
catch(java.lang.ClassNotFoundException e)
{
System.err.println("dbconnaccess():"+e.getMessage());
}
catch(java.sql.SQLException exp)
{
System.err.println("dbconnaccess():"+exp.getMessage());
}
}
public Statement getstmt()
{
return stmt;
}
public ResultSet exesql(String sql)
{
rs=null;
try {rs=stmt.executeQuery(sql);}
catch (SQLException ex) { System.err.println("aq.excutequery:"+ex.getMessage());}
return rs;
}
public boolean executeupdate(String sql)
{
try{
stmt.executeUpdate(sql);
return true;
}
catch(SQLException ea) {System.err.println("aq.executeupdate:"+ea.getMessage()); }
return false;
}
public void closedb()
{
try{
if(rs != null)
rs.close();
if(stmt != null)
stmt.close();
if(!conn.isClosed() || conn != null)
conn.close();
}
catch(Exception e){System.out.println(e.toString());}
}
}
JSP代码如下
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*"%>
<jsp:useBean id="db" scope="page" class="opendb.opendb"/>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>用户登录</title>
</head>
<body >
<center>
<%
String uid=request.getParameter("staff_name");
String pwd=request.getParameter("password");
String query="select * from staff where staff_name='"+uid+"' and password='"+pwd+"'";
ResultSet rs = db.exesql(query);
if(rs.next())
{
rs.close();
%>
welcome <%=uid %>
<%
}
else
{
rs.close();
%>
<p>sorry!the password is incorrect!</p>
<p><input type="button" name="Button2" value="back" onClick="backward()"></p>
<%}
%>
</center>
</body>
</html>
错误信息
HTTP Status 500 -
--------------------------------------------------------------------------------
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: opendb/opendb (Unsupported major.minor version 49.0)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:244)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
root cause
java.lang.UnsupportedClassVersionError: opendb/opendb (Unsupported major.minor version 49.0)
java.lang.ClassLoader.defineClass0(Native Method)
java.lang.ClassLoader.defineClass(ClassLoader.java:539)
java.security.SecureClassLoader.defineClass(SecureClassLoader.java:123)
org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:1634)
..........
..........
note The full stack trace of the root cause is available in the Apache Tomcat/5.0.28 logs.
JAVABEAN的包如下
package opendb;
import java.sql.*;
public class opendb
{
String dbdriver="org.gjt.mm.mysql.driver";
String url="jdbc:mysql:/localhost/staffinfo";
String user="root";
String password="Lee_0593";
Connection conn=null;
ResultSet rs=null;
Statement stmt;
public opendb()
{
try{
Class.forName(dbdriver);
conn= DriverManager.getConnection(url,user,password);
stmt=conn.createStatement();
}
catch(java.lang.ClassNotFoundException e)
{
System.err.println("dbconnaccess():"+e.getMessage());
}
catch(java.sql.SQLException exp)
{
System.err.println("dbconnaccess():"+exp.getMessage());
}
}
public Statement getstmt()
{
return stmt;
}
public ResultSet exesql(String sql)
{
rs=null;
try {rs=stmt.executeQuery(sql);}
catch (SQLException ex) { System.err.println("aq.excutequery:"+ex.getMessage());}
return rs;
}
public boolean executeupdate(String sql)
{
try{
stmt.executeUpdate(sql);
return true;
}
catch(SQLException ea) {System.err.println("aq.executeupdate:"+ea.getMessage()); }
return false;
}
public void closedb()
{
try{
if(rs != null)
rs.close();
if(stmt != null)
stmt.close();
if(!conn.isClosed() || conn != null)
conn.close();
}
catch(Exception e){System.out.println(e.toString());}
}
}
JSP代码如下
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*"%>
<jsp:useBean id="db" scope="page" class="opendb.opendb"/>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>用户登录</title>
</head>
<body >
<center>
<%
String uid=request.getParameter("staff_name");
String pwd=request.getParameter("password");
String query="select * from staff where staff_name='"+uid+"' and password='"+pwd+"'";
ResultSet rs = db.exesql(query);
if(rs.next())
{
rs.close();
%>
welcome <%=uid %>
<%
}
else
{
rs.close();
%>
<p>sorry!the password is incorrect!</p>
<p><input type="button" name="Button2" value="back" onClick="backward()"></p>
<%}
%>
</center>
</body>
</html>
错误信息
HTTP Status 500 -
--------------------------------------------------------------------------------
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: opendb/opendb (Unsupported major.minor version 49.0)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:244)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
root cause
java.lang.UnsupportedClassVersionError: opendb/opendb (Unsupported major.minor version 49.0)
java.lang.ClassLoader.defineClass0(Native Method)
java.lang.ClassLoader.defineClass(ClassLoader.java:539)
java.security.SecureClassLoader.defineClass(SecureClassLoader.java:123)
org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:1634)
..........
..........
note The full stack trace of the root cause is available in the Apache Tomcat/5.0.28 logs.