Servlet.service() for servlet jsp threw exception
java.lang.NullPointerException
at bean.db.common.dbOpertaion.executeQuery(dbOpertaion.java:18)
at bean.db.bookOPBean.selectBookBySQL(bookOPBean.java:102)
at bean.db.bookOPBean.selectBookTop6(bookOPBean.java:73)
at org.apache.jsp.index_jsp._jspService(index_jsp.java:117)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:384)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:228)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:216)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:634)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:445)
at java.lang.Thread.run(Unknown Source)

解决方案 »

  1.   

    at bean.db.common.dbOpertaion.executeQuery(dbOpertaion.java:18)
    对应的dbOpertaion.java代码如下:
    package bean.db.common;
    import java.sql.Connection;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;
    import java.sql.*;public class dbOpertaion {
        /**
         * 执行SQL查询语句
         */
        public ResultSet executeQuery(String sqlString){
            if(sqlString==null) return null;
            Connection conn=openDB();
            ResultSet rs=null;//结果记录集
            Statement sql=null;//SQL语句对象
            try{
                sql=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY); //这是出问题的18行
                rs=sql.executeQuery(sqlString);
                return rs;
            } catch (SQLException e) {
                e.printStackTrace();
                rs=null;
            }
            closeDB(conn);
            return rs;
        }
        /**
         * 执行SQL更新语句,返回影响的行数
         */
        public int executeUpdate(String sqlString){
            if(sqlString==null) return 0;
            Connection conn=openDB();
            Statement sql=null;//SQL语句对象
            int i=0;//影响的行数
            try{
                sql=conn.createStatement();
                i=sql.executeUpdate(sqlString);
            } catch (SQLException e) {
                e.printStackTrace();
                i=0;
            }
            closeDB(conn);
            return i;
        }
        /**
         * 打开数据库连接
         */
        public Connection openDB(){
            dbconn dbconnOBject=new dbconn();//数据库连接对象
            Connection dbcon=dbconnOBject.getDBConn();//得到数据库连接
            return dbcon;
        }
        /**
         * 关闭数据库连接
         */
        public void closeDB(Connection conn){
            if(conn!=null){
                try {
                    conn.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
        }
    }
      

  2.   

    at bean.db.bookOPBean.selectBookBySQL(bookOPBean.java:102)
    bookOPBean代码如下:
    public class bookOPBean extends dbOpertaion{
        private int bookid=0;
        private bookBean book=new bookBean();
        private int bookTypeId=0;
        /**
         * 查询出书藉资料
         */
        public ArrayList selectBook(String bookname){
            //------构造SQL语句------
            String sqlString=null;
            if(bookname==null||bookname.trim().length()<=0)
                sqlString=new String("select * from book");
            else
                sqlString=new String("select * from book where book_name like '%"+bookname+"%'");
            sqlString=sqlString+" order by add_time desc";
            //------查询出数据------
            ArrayList rsArrayList=selectBookBySQL(sqlString);
            return rsArrayList;
        }
        /**
         * 查询出最近的100本书
         */
        public ArrayList selectBook100(){
            String sqlString=new String("select top 100 * from book order by add_time desc");
            ArrayList rsArrayList=selectBookBySQL(sqlString);
            return rsArrayList;
        }
        /**
         * 查询出特价书藉的前7本,5折用其以下的
         */
        public ArrayList selectBookMiniPriceTop7(){
            String sqlString=new String("select top 7 * from book where price_rebate<=5 order by add_time desc");
            ArrayList rsArrayList=selectBookBySQL(sqlString);
            return rsArrayList;
        }
        /**
         * 查询出特价书藉的前6本,5折用其以下的
         */
        public ArrayList selectBookMiniPriceTop6(){
            String sqlString=new String("select top 6 * from book where price_rebate<=5 order by add_time desc");
            ArrayList rsArrayList=selectBookBySQL(sqlString);
            return rsArrayList;
        }
        /**
         * 查询出所有特价书藉,5折用其以下的
         */
        public ArrayList selectBookMiniPrice(){
            String sqlString=new String("select * from book where price_rebate<=5 order by add_time desc");
            ArrayList rsArrayList=selectBookBySQL(sqlString);
            return rsArrayList;
        }
        /**
         * 查询出最近录入的6本新书
         */
        public ArrayList selectBookTop6(){
            //------构造SQL语句------
            String sqlString=new String("select top 6 * from book order by add_time desc");
            //------查询出数据------
            ArrayList rsArrayList=selectBookBySQL(sqlString);  //这是出问题的73行
            return rsArrayList;
        }
        /**
         * 查询出某个分类的前6本书藉,并按时间排序
         */
        public ArrayList selectBookByTypeTop6(){
            //------构造SQL语句------
            String sqlString=new String("select top 6 * from book where type_id="+
                    bookTypeId+ " order by add_time desc");
            //------查询出数据------
            ArrayList rsArrayList=selectBookBySQL(sqlString);
            return rsArrayList;
        }
        /**
         * 查询出某个分类的书藉的数据,并按时间排序
         */
        public ArrayList selectBookByType(){
            //------构造SQL语句------
            String sqlString=new String("select * from book where type_id="+
                    bookTypeId+ " order by add_time desc");
            //------查询出数据------
            ArrayList rsArrayList=selectBookBySQL(sqlString);
            return rsArrayList;
        }
        /**
         * 根据SQL语句查询出书藉,并放入ArrayList
         */
        public ArrayList selectBookBySQL(String sqlString){
            ResultSet rs=this.executeQuery(sqlString);   //出问题的102行
            //------将查询出的数据放入ArrayList中------
            ArrayList rsArrayList=new ArrayList();
            try{
                int i=0;
                while(rs.next()){
                    rsArrayList.add(i,dealARecord(rs));
                    i++;
                }
            } catch (Exception e) {
                e.printStackTrace();
                rsArrayList=null;
            }
            return rsArrayList;
        }
        /**
         * 一条记录的处理,私有方法
         */
        private bookBean dealARecord(ResultSet rs){
            bookBean book=new bookBean();
            try{
                book.setBookid(rs.getLong("book_id"));
                book.setBookname(rs.getString("book_name"));
                book.setAuthor(rs.getString("author"));
                book.setPublisher(rs.getString("publisher"));
                book.setPrice(rs.getFloat("price"));
                book.setPrice_rebate(rs.getFloat("price_rebate"));
                book.setPublish_date(rs.getDate("publish_date"));
                book.setPagecount(rs.getInt("pagecount"));
                book.setFormat(rs.getString("format"));
                book.setSimple_content(rs.getString("simple_content"));
                book.setTypeid(rs.getInt("type_id")); 
                //------图片处理------
                InputStream in=rs.getBinaryStream("book_image");
                if(in!=null){
                    try{
                        int len = 10*1024*1024;
                        byte[] P_Buf = new byte[len];
                        int j;
                        while ((j = in.read(P_Buf)) != -1) {
                            byte[] oldByteArray=book.getImageByteArray();
                            byte[] newByteArray=null;
                            if(oldByteArray!=null){
                                newByteArray=new byte[oldByteArray.length+j];
                                for(int k=0;k<j;k++)
                                    newByteArray[oldByteArray.length+k]=P_Buf[k];
                            }else{
                                newByteArray=new byte[j];
                                for(int k=0;k<j;k++)
                                    newByteArray[k]=P_Buf[k];
                            }  
                            book.setImageByteArray(newByteArray);
                        }
                    }catch(NullPointerException e1){
                        e1.printStackTrace();
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            return book;
        }
        /**
         * 根据ID号查询出一本书藉的资料
         */
        public bookBean selectBookById(int bookid){
            //------构造SQL语句------
            String sqlString="select * from book where book_id="+bookid;
            //------查询出数据------
            ResultSet rs=this.executeQuery(sqlString);
            //------将查询出的数据放入bookBean中------
            bookBean book=new bookBean();
            try{
                if(rs.next()){      
                    book=dealARecord(rs);
                }
            } catch (Exception e) {
                e.printStackTrace();
                book=null;
            }
            return book;
        }
        /**
         * 新书上架
         */
        public int insertBook(ActionForm form){
            int i=0;
            //------从ActionForm对象中得到数据------
            String bookname=((addBookForm)form).getBookname();
            String typeid=((addBookForm)form).getTypeid();
            String author=((addBookForm)form).getAuthor();
            String publisher=((addBookForm)form).getPublisher();
            String price=((addBookForm)form).getPrice();
            String price_rebate=((addBookForm)form).getPrice_rebate();
            String publishdate=((addBookForm)form).getPublishdate();
            String pagecount=((addBookForm)form).getPagecount();
            String format=((addBookForm)form).getFormat();
            String simple_content=((addBookForm)form).getSimple_content();
            //------构造SQL语句------
            String sqlString="insert into book(book_name,author,publisher"
                +",price,price_rebate,publish_date,pagecount,format,simple_content"
                +",type_id) values('"+bookname+"','"+author+"','"+publisher
                +"',"+price+","+price_rebate+",'"+publishdate+"',"+pagecount
                +",'"+format+"','"+simple_content+"',"+typeid+")";
            //System.out.println(sqlString);
            //------执行SQL语句------
            i=this.executeUpdate(sqlString);
            return i;
        }
        /**
         * 删除一本书
         */
        public int deleteBook(int bookid){
            int i=0;
            if(bookid<=0) return i;
            String sqlString="delete from book where book_id="+bookid;
            i=this.executeUpdate(sqlString);
            return i;
        }
        /**
         * 更新一本书的书藉信息
         */
        public int updateBook(ActionForm form,int bookid){
            int i=0;
            //------从ActionForm对象中得到数据------
            String bookname=((addBookForm)form).getBookname();
            String typeid=((addBookForm)form).getTypeid();
            String author=((addBookForm)form).getAuthor();
            String publisher=((addBookForm)form).getPublisher();
            String price=((addBookForm)form).getPrice();
            String price_rebate=((addBookForm)form).getPrice_rebate();
            String publishdate=((addBookForm)form).getPublishdate();
            String pagecount=((addBookForm)form).getPagecount();
            String format=((addBookForm)form).getFormat();
            String simple_content=((addBookForm)form).getSimple_content();
            //------构造SQL语句------
            String sqlString="update book set book_name='" +bookname+"',author='" +
             author+"',publisher='"+publisher+"',price="+price+",price_rebate=" +
             price_rebate+",publish_date='"+publishdate+"',pagecount=" +
             pagecount+",format='"+format+"',simple_content='"+simple_content+
             "',type_id="+typeid+" where book_id="+bookid;
            //System.out.println(sqlString);
            //------执行SQL语句------
            i=this.executeUpdate(sqlString);
            return i;
        }
        public int getBookid() {
            return bookid;
        }
        public void setBookid(int bookid) {
            this.bookid = bookid;
            this.book=this.selectBookById(bookid);     
        }
        public bookBean getBook() {
            return book;
        }
        public void setBook(bookBean book) {
            this.book = book;
        }
        public int getBookTypeId() {
            return bookTypeId;
        }
        public void setBookTypeId(int bookTypeId) {
            this.bookTypeId = bookTypeId;
        }
    }
      

  3.   

       贴这么多都没人看的,贴出重点就行了 !
    sql=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);   把参数去掉呢 ?--> sql = conn.createStatement();
      

  4.   

    SQLServer以前在XP下老不好使得打补丁。
    顺便问下楼主打了没?
    还是SQLServer2005版本不用打补丁了?