救命啊!!为什么还是错

alan817 alan817 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
package myConnection;

import java.lang.*;
import java.sql.*;

public class connDB {

Connection conn;
ResultSet rs;
ResultSetMetaData rsmd;
Statement stmt;
//String driverName="com.microsoft.jdbc.sqlserver.SQLServerDriver";
//String jdbcURL="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=Test";
String driverName="sun.jdbc.odbc.JdbcOdbcDriver";
String jdbcURL="jdbc:odbc:Test";
String username="Alan";
String password="";


public connDB(){
conn=null;
rs=null;
rsmd=null;
stmt=null;
try{
Class.forName(driverName);
}
catch(ClassNotFoundException e){
}
}

public ResultSet execQuery(String sql){
if(sql==null){
System.out.println("查询语句不能为空。");
}
try{
conn=DriverManager.getConnection(jdbcURL,username,password);
stmt=conn.createStatement();
rs=stmt.executeQuery(sql);
}
catch(SQLException eq){
}
return rs;
}

public int execUpdate(String sql){
int result=0;
try{
stmt=conn.createStatement();
stmt.executeUpdate(sql);
}
catch(SQLException eu){
}
return result;
}

public void rsClose() throws Exception{
if(rs!=null){
rs.close();
rs=null;
}
}
public void stmtClose() throws Exception{
if(stmt!=null){
stmt.close();
stmt=null;
}
}
public void connClose() throws Exception{
if(conn!=null || !conn.isClosed()){
conn.close();
conn=null;
}
}
public void closeAll() throws Exception{
rsClose();
stmtClose();
connClose();
}


}


jsp也面:
<jsp:useBean id="connDB" class="myConnection.connDB" scope="page"/>
//String sql1="update userInfo set addr='hhh' where id=1";
String sql2="select * from userInfo";
ResultSet rs=connDB.execQuery(sql2);

这样写的没提示什么错误,但是加上rs.next();就出现错误。

极度郁闷~~
请各位大侠帮帮忙呀


错误信息:
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.testSql_jsp._jspService(testSql_jsp.java:77)
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.



...全文

相关推荐

评论 17
收藏 已收藏
分享
返回顶部
alan817
Web 开发 81,108 成员 341,721 内容