| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 886 人关注过本帖
标题:关于JSP+SQL SERVER 2000的编程问题
取消只看楼主 加入收藏
jacky123
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2006-4-11
收藏
 问题点数:0 回复次数:2 
关于JSP+SQL SERVER 2000的编程问题

大家帮我看看,这个JAVABEAN和check两个代码,是关于连接数据库和登陆验证的,老是无法正确运行。有人看了说是check中的if(rs.next())有问题,哪位高人能帮我解答一下。

JAVABEAN:

package com.bwm.db;
import java.sql.*;
public class Condb{
String servername="localhost";
String drivername="com.microsoft.jdbc.sqlserver.SQLServerDriver";
String url="jdbc:microsoft:sqlserver://servername:1433;DatabaseName=db_Scenince;user=sa;password=123";
Connection con=null;
ResultSet rs=null;
public Condb(){
try{
Class.forName(drivername);
}catch(java.lang.ClassNotFoundException e){
System.err.println(e.getMessage());
}
}
public ResultSet executeQuery(String sql){
try{
con=DriverManager.getConnection(url);
Statement stmt=con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
rs=stmt.executeQuery(sql);
}catch(SQLException ex){
System.err.println(ex.getMessage());
}
return rs;
}
public int executeUpdate(String sql){
int result=0;
try{
con=DriverManager.getConnection(url);
Statement stmt=con.createStatement();
result=stmt.executeUpdate(sql);
}catch(SQLException ex){
System.err.println(ex.getMessage());
}
return result;
}
public void close(){
try{
if(rs!=null){
rs.close();
}
}catch(Exception e){
System.err.println(e.getMessage());
}
try{
if(con!=null){
con.close();
}
}catch(Exception e){
System.err.println(e.getMessage());
}
}
}

搜索更多相关主题的帖子: SQL SERVER JSP 数据库 
2006-04-11 10:10
jacky123
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2006-4-11
收藏
得分:0 

check代码:

<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" %>
<% request.setCharacterEncoding("gb2312"); %>
<%@ page import="com.bwm.page.Show"%>
<%@ page import="com.bwm.db.Condb"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>

<body>
<%
Condb con=new Condb();
//Connection conn=con.getConnection();
Show show=new Show();
String name=request.getParameter("name");
String password=request.getParameter("password");
String sql="select * from tb_Person where Username='"+name+"' and Password='"+password+"'";
ResultSet rs=con.executeQuery(sql);
if(rs.next()){
String strsql=rs.getString(1);
session.setAttribute("name",name);
session.setAttribute("password",password);
session.setAttribute("groupid",strsql);
response.sendRedirect("index.htm");
}else{
out.print(show.errorBox("你输入的用户名或密码有误","错误信息"));
out.close();
}
//if(conn!=null){
// conn.close();
//}
con.close();
%>

</body>
</html>

2006-04-11 10:10
jacky123
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2006-4-11
收藏
得分:0 
说是空指针错误,

type Exception report

message

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

exception

org.apache.jasper.JasperException
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:358)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)


root cause

java.lang.NullPointerException
org.apache.jsp.user.check_jsp._jspService(check_jsp.java:67)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)


note The full stack trace of the root cause is available in the Tomcat logs

2006-04-11 10:11
快速回复:关于JSP+SQL SERVER 2000的编程问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016393 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved