关于一个数据库连接不能创建多个statement?????急!!!!在线等

jerrycyj 2005-05-05 01:26:18

刘兴军 2005-05-05 12:56:59
首先,创建一个类mysql,其中有两个属性private Statement [] stmts=null;
public ResultSet [] Res=null;//查询结果集
然后,创建方法
public void setStmts(String sql[])throws Exception{
for(int i=0;i<sql.length;i++){
if(stmts[i]==null) stmts[i]=conn.createStatement();
}
}来设置stmts数组;
接着,创建的方法
public void getResultset(String sql[]) throws SQLException {
if(sql.length>0){
this.Res = new ResultSet[sql.length];
for (int i = 0; i < sql.length; i++) {
this.Res[i] = this.executeQuery(stmts[i],sql[i]);
}
}
}
生成ResultSet数组,其中调用了下面方法
public ResultSet executeQuery(Statement st,String sql)throws SQLException{
if (st != null) {
return st.executeQuery(sql);
}
else return null;
}

注:sql数组为查询语句.(因为涉及多张表操作,所以只好这样.)
在jsp中,我是这样使用的.
mysql=new Mysql();//+++++
mysql.setQuery();//设置查询语句
mysql.setStmts(mysql.query);//创建Statement数组
mysql.getResultset(mysql.query);//得到ResultSet数组
问题是,我在jsp中使用时,运行不通过.
错误提示显示如下:
java.lang.NullPointerException

at bulldream.Mysql.setStmts(Mysql.java:52) //这是我自己创建的类,问题可能就在这里!
at org.apache.jsp.Aa1$jsp._jspService(Aa1$jsp.java:105)

at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:107)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)

at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:201)

at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:381)

at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:473)

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:243)

at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)

at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)

at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)

at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:190)

at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)

at org.apache.catalina.valves.CertificatesValve.invoke(CertificatesValve.java:246)

at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)

at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)

at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)

at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2347)

at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)

at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)

at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)

at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)

at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:170)

at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)

at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)

at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)

at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)

at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)

at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)

at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)

at org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:1027)

at org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:1125)

at java.lang.Thread.run(Thread.java:534)
...全文
64 1 点赞 打赏 收藏 举报
写回复
1 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
anhy 2005-05-05
Mysql.java的52行是哪句话,那里出现运行时错误:空指针(空地址)操作
  • 打赏
  • 举报
回复
相关推荐
发帖
Web 开发
创建于2007-09-28

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2005-05-05 01:26
社区公告
暂无公告