我写了一个数据库连接的JAVABEAN,和一个登陆页面的JSP但是登陆有问题,请大家帮我看看。

freedom1980 2004-08-30 11:17:05
javabean:
package myclass;
import java.net.SocketException;
import java.sql.*;
import java.sql.*;
public class ConnectBean {

private Connection conn=null;
private Statement stmt=null;
ResultSet rst=null;
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=example1";
String user="sa";
String password="ms";
public ConnectBean ()
{

try{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");



}

catch (ClassNotFoundException ex) {
ex.printStackTrace();
}


}

public ResultSet executeQuery(String sql){

try{

Connection conn= DriverManager.getConnection(url,user,password);
stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
rst=executeQuery(sql);
}catch(SQLException e){
System.out.println("the error:"+e.toString());
}
return rst;
}

public void excuteUpdate(String sql){

try{
Connection conn=DriverManager.getConnection(url,user,password);
stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
rst=stmt.executeQuery(sql);
}catch(SQLException e){
System.out.println("sqlexception error:"+e.toString());
}
}
public void closeStmt(){
try{
stmt.close();
}catch(SQLException e){
e.printStackTrace();
}
}
public void closeConn(){
try{
conn.close();
}catch(SQLException e){
e.printStackTrace();
}
}
public void closeRst(){
try{
rst.close();
}catch(SQLException e){
e.printStackTrace();
}
}
}
JSP:
<%@ page language="java" contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*,java.util.*"%>
<jsp:useBean id="con" scope="page" class="myclass.ConnectBean" />
<html>
<head>
<script language="javascript">
function checkform(rst){

var id1=document.loginform.loginid.value;
var psw1=document.loginform.loginpsw.value;
if(id1=="")
{
alert("the id is not right please input it again");
ducument.loginform.loginid.focus();
return false;
}
else if(psw1=="")
{
alert("the psws is not right please input it again");
ducument.loginform.loginpsw.focus();
return false;
}


else if(rst){
alert("ok");
document.loginform.action="example3.jsp";
document.loginform.submit();
return true;

}
}
</script>
</head>
<body>
<%
int loginid=Integer.parseInt(request.getParameter("loginid"));
String loginpsw=request.getParameter("loginpsw");
String sql="SELECT * FROM LOGINTABLE WHERE ID='"+loginid+"'AND PSW='"+loginpsw+"'";
%>
<form name=loginform>
<p align=center>THE SUPERMARKET MANGEMENT SYSTEM
<p align=center> designer: Li Guojiang
<p align=center>please input the login ID:
<input type=text name="loginid" value="" maxlength=6 size=6>
<p align=center>please input the login password:
<input type=text name="loginpsw" value="" maxlength=8 size=8>
<P align=center>please choose the role:
<select name=menu>
<option value="customer">customer
<option value="saleman">saleman
<option value="buy">buy
<option value="manger">manger
</select>
<p align=center>
<input type=submit name=submitbutton value="submit" onClick="checkform(<%=con.executeQuery(sql).toString()%>)">
<input type=reset name=resetbutton value="reset">
</body>
</html>
运行http://localhost:8080/examples/login.jsp后

TOMCAT4。1启动的DOS窗口里面提示:
the error:java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Erro
r establishing socket.
说明连接出错了。 是端口有问题, 肯定不是 因为我有写了一个测试的JSP
如下:
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*"%>
<HTML>
<title>jsp链接sql server例子</title>
<BODY>
<%
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=example1";
String user="sa";
String password="ms";
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Connection conn= DriverManager.getConnection(url,user,password);
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
ResultSet rs=stmt.executeQuery("select * from logintable");
while (rs.next())
{
%>

您的第一个字段内容为:<%=rs.getString(1)%>

您的第二个字段内容为:<%=rs.getString(2)%>
<%

}

%>

<%out.print("数据库操作成功,恭喜你");%>

<%

rs.close();

stmt.close();

conn.close();

%>
运行http://localhost:8080/examples/test1.jsp
结果正确。
我就不明白了,为什么我的BEAN里面连接数据库会出错。

...全文
97 点赞 收藏 3
写回复
3 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
dafei0320 2004-08-31
帮你顶先---
检查连接库程序!
回复
freedom1980 2004-08-30
每人知道吗
我自己来顶顶哎。。。。。。。
回复
freedom1980 2004-08-30
我再附叫login.jsp运行后
页面的错误提示:Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: null
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:254)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:494)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2417)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:193)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:781)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:549)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:589)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:666)
at java.lang.Thread.run(Thread.java:536)


root cause

java.lang.NumberFormatException: null
at java.lang.Integer.parseInt(Integer.java:394)
at java.lang.Integer.parseInt(Integer.java:476)
at org.apache.jsp.login_jsp._jspService(login_jsp.java:67)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:137)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:210)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:494)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2417)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:193)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:781)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:549)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:589)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:666)
at java.lang.Thread.run(Thread.java:536)


回复
相关推荐
发帖
Web 开发
创建于2007-09-28

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2004-08-30 11:17
社区公告
暂无公告