难道update时不能用数组吗?
大家帮忙啦,急~~~!!
package depots;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.SQLException;
import depots.*;
public class SaveBean22 {
private String[] proid;
private String[] enum;
public String[] getProid() {
return proid;
}
public void setProid(String[] proid) {
this.proid = TOGBKFY.toGBK(proid);
}
public String[] getEnum() {
return enum;
}
public void setEnum(String[] enum) {
this.enum =TOGBKFY.toGBK(enum);
}
public String getSave(){
try {
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Connection con=DriverManager.getConnection("jdbc:microsoft:sqlserver://127.0.0.1:1433;User=sa;");
con.setCatalog("DataDemo");
PreparedStatement sta = con.prepareStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
for(int i=0;i<proid.length;i++)
{
String sql="update TabDemo set enum="+enum[i]+" where proid ='"+proid[i]+"'";
sta.executeUpdate(sql);
}
con.commit();
sta.close();
con.close();
sta=null;
con=null;
return "<font color=green>成功 </font>";
} catch (ClassNotFoundException e) {
e.printStackTrace();
return "<font color=green>不成功 </font>";
} catch (SQLException e) {
e.printStackTrace();
return "<font color=green>不成功 </font>";
}
}
}
19 个解决方案
#1
错误代码是什么!
#2
String sql="update TabDemo set enum="+enum[i]+" where proid ='"+proid[i]+"'";
这行有错
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~``
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:367)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:293)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:240)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:286)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:562)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:974)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:205)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:562)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:974)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:177)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:149)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:149)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:562)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:974)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:156)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:562)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:974)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:203)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:637)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:484)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:568)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:631)
at java.lang.Thread.run(Thread.java:536)
root cause
java.lang.NullPointerException
at depots.SaveBean22.getSave(SaveBean22.java:92)
at org.apache.jsp.depot.cklh3_jsp._jspService(cklh3_jsp.java:67)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:136)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:320)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:293)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:240)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:286)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:562)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:974)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:205)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:562)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:974)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:177)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:149)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:149)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:562)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:974)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:156)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:562)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:974)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:203)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:637)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:484)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:568)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:631)
at java.lang.Thread.run(Thread.java:536)
这行有错
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~``
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:367)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:293)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:240)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:286)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:562)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:974)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:205)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:562)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:974)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:177)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:149)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:149)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:562)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:974)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:156)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:562)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:974)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:203)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:637)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:484)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:568)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:631)
at java.lang.Thread.run(Thread.java:536)
root cause
java.lang.NullPointerException
at depots.SaveBean22.getSave(SaveBean22.java:92)
at org.apache.jsp.depot.cklh3_jsp._jspService(cklh3_jsp.java:67)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:136)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:320)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:293)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:240)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:286)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:562)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:974)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:205)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:562)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:974)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:177)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:149)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:149)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:562)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:974)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:156)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:562)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:974)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:203)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:637)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:484)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:568)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:631)
at java.lang.Thread.run(Thread.java:536)
#3
cklh3.jsp有空指针.
#4
PreparedStatement sta = con.prepareStatement("update TabDemo set enum=? where proid =?");
for(int i=0;i<proid.length;i++)
{
sta.setString(1,enum[i]);
sta.setString(2,proid[i]);
sta.executeUpdate();
}
大哥你基本语法都是错的
for(int i=0;i<proid.length;i++)
{
sta.setString(1,enum[i]);
sta.setString(2,proid[i]);
sta.executeUpdate();
}
大哥你基本语法都是错的
#5
String sql="update TabDemo set enum='"+enum[i]+"' where proid ='"+proid[i]+"'";
enum 是String
enum 是String
#6
for(int i=0;i<proid.length;i++)
{
String sql="update intidy set enum="+enum[i]+" where proid ='"+proid[i]+"'";
sta.executeUpdate(sql);
}
这样就有错,只要是传的数组就有错
如果传的是单独一条记录不是数组就没错
String sql="update intidy set enum="+enum+" where proid ='"+proid+"'";
sta.executeUpdate(sql);
我需要数组的,到底该怎么解决啊?
{
String sql="update intidy set enum="+enum[i]+" where proid ='"+proid[i]+"'";
sta.executeUpdate(sql);
}
这样就有错,只要是传的数组就有错
如果传的是单独一条记录不是数组就没错
String sql="update intidy set enum="+enum+" where proid ='"+proid+"'";
sta.executeUpdate(sql);
我需要数组的,到底该怎么解决啊?
#7
批量更新不是这么个更新法,要用addBatch
#8
空指针,说明你enum数组中的元素本来就有问题!!
还有enum字段是什么类型,varchar要加单引号的!
还有这根本就不叫批量更新,楼上说了批量更新的方法!!
还有enum字段是什么类型,varchar要加单引号的!
还有这根本就不叫批量更新,楼上说了批量更新的方法!!
#9
批量更新使用addBatch()与executeBatch()
#10
瀑布汗...
SQL语句你怎么用数组....
SQL语句你怎么用数组....
#11
他的代码
for(int i=0;i<proid.length;i++)
{
String sql="update TabDemo set enum="+enum[i]+" where proid ='"+proid[i]+"'";
sta.executeUpdate(sql);
}
就是不断变化参数嘛,这个就是可以用批量更新来做!
for(int i=0;i<proid.length;i++)
{
String sql="update TabDemo set enum="+enum[i]+" where proid ='"+proid[i]+"'";
sta.executeUpdate(sql);
}
就是不断变化参数嘛,这个就是可以用批量更新来做!
#12
应该这样写:
PreparedStatement sta = con.prepareStatement("update TabDemo set enum=? where proid =?");
for(int i=0;i<proid.length;i++)
{
sta.setString(1,enum[i]);
sta.setString(2,proid[i]);
sta.addBatch();
}
sta.executeBatch();
PreparedStatement sta = con.prepareStatement("update TabDemo set enum=? where proid =?");
for(int i=0;i<proid.length;i++)
{
sta.setString(1,enum[i]);
sta.setString(2,proid[i]);
sta.addBatch();
}
sta.executeBatch();
#13
Sunny319(努力学习java中.)
用
PreparedStatement sta = con.prepareStatement("update TabDemo set enum=? where proid =?");
for(int i=0;i<proid.length;i++)
{
sta.setString(1,enum[i]);
sta.setString(2,proid[i]);
sta.addBatch();
}
sta.executeBatch();
有错,报
H:\MPL\WEB-INF\classes\depots\SaveBean22.java:91: cannot resolve symbol
symbol : class PreparedStatement
location: class depots.SaveBean22
PreparedStatement sta = con.prepareStatement("update intidy set enum=? where proid =?");
^
1 error
Tool completed with exit code 1
我的问题怎么解决啊,我是菜鸟不懂的,谁帮忙解决啊,啊5555555
用
PreparedStatement sta = con.prepareStatement("update TabDemo set enum=? where proid =?");
for(int i=0;i<proid.length;i++)
{
sta.setString(1,enum[i]);
sta.setString(2,proid[i]);
sta.addBatch();
}
sta.executeBatch();
有错,报
H:\MPL\WEB-INF\classes\depots\SaveBean22.java:91: cannot resolve symbol
symbol : class PreparedStatement
location: class depots.SaveBean22
PreparedStatement sta = con.prepareStatement("update intidy set enum=? where proid =?");
^
1 error
Tool completed with exit code 1
我的问题怎么解决啊,我是菜鸟不懂的,谁帮忙解决啊,啊5555555
#14
我JDK是 j2sdk1.4.1_02 的
不会跟着有关吧???
不会跟着有关吧???
#15
import java.sql.PreparedStatement;
加上这个
加上这个
#16
没有引进包文件:
加载import java.sql.PreparedStatement;就可以了!
加载import java.sql.PreparedStatement;就可以了!
#17
批量更新
1、Statement
Statement sm = cn.createStatement();
sm.addBatch(sql1);
sm.addBatch(sql2);
...
sm.executeBatch()
一个Statement对象,可以执行多个sql语句以后,批量更新。这多个语句可以是delete、update、insert等或兼有
2、PreparedStatement
PreparedStatement ps = cn.preparedStatement(sql);
{
ps.setXXX(1,xxx);
...
ps.addBatch();
}
ps.executeBatch();
一个PreparedStatement,可以把一个sql语句,变换参数多次执行,一次更新。
1、Statement
Statement sm = cn.createStatement();
sm.addBatch(sql1);
sm.addBatch(sql2);
...
sm.executeBatch()
一个Statement对象,可以执行多个sql语句以后,批量更新。这多个语句可以是delete、update、insert等或兼有
2、PreparedStatement
PreparedStatement ps = cn.preparedStatement(sql);
{
ps.setXXX(1,xxx);
...
ps.addBatch();
}
ps.executeBatch();
一个PreparedStatement,可以把一个sql语句,变换参数多次执行,一次更新。
#18
try {
con = source.getConnection();
con.setAutoCommit(false);
con.setTransactionIsolation (Connection.TRANSACTION_SERIALIZABLE);
stmt = con.createStatement();
stmt.executeUpdate(updatesql);
con.commit();
}
} catch (Exception e) {
e.printStackTrace();
try {
con.rollback();
} catch (Exception ex) {
ex.printStackTrace();
}
} finally {
if (stmt != null) {
stmt.close();
}
if (con != null) {
con.close();
}
}
#19
我这个也是批量提交的
#20
#1
错误代码是什么!
#2
String sql="update TabDemo set enum="+enum[i]+" where proid ='"+proid[i]+"'";
这行有错
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~``
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:367)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:293)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:240)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:286)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:562)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:974)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:205)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:562)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:974)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:177)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:149)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:149)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:562)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:974)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:156)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:562)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:974)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:203)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:637)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:484)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:568)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:631)
at java.lang.Thread.run(Thread.java:536)
root cause
java.lang.NullPointerException
at depots.SaveBean22.getSave(SaveBean22.java:92)
at org.apache.jsp.depot.cklh3_jsp._jspService(cklh3_jsp.java:67)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:136)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:320)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:293)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:240)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:286)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:562)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:974)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:205)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:562)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:974)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:177)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:149)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:149)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:562)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:974)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:156)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:562)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:974)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:203)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:637)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:484)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:568)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:631)
at java.lang.Thread.run(Thread.java:536)
这行有错
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~``
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:367)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:293)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:240)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:286)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:562)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:974)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:205)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:562)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:974)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:177)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:149)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:149)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:562)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:974)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:156)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:562)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:974)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:203)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:637)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:484)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:568)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:631)
at java.lang.Thread.run(Thread.java:536)
root cause
java.lang.NullPointerException
at depots.SaveBean22.getSave(SaveBean22.java:92)
at org.apache.jsp.depot.cklh3_jsp._jspService(cklh3_jsp.java:67)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:136)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:320)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:293)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:240)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:286)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:562)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:974)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:205)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:562)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:974)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:177)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:149)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:149)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:562)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:974)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:156)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:562)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:974)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:203)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:637)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:484)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:568)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:631)
at java.lang.Thread.run(Thread.java:536)
#3
cklh3.jsp有空指针.
#4
PreparedStatement sta = con.prepareStatement("update TabDemo set enum=? where proid =?");
for(int i=0;i<proid.length;i++)
{
sta.setString(1,enum[i]);
sta.setString(2,proid[i]);
sta.executeUpdate();
}
大哥你基本语法都是错的
for(int i=0;i<proid.length;i++)
{
sta.setString(1,enum[i]);
sta.setString(2,proid[i]);
sta.executeUpdate();
}
大哥你基本语法都是错的
#5
String sql="update TabDemo set enum='"+enum[i]+"' where proid ='"+proid[i]+"'";
enum 是String
enum 是String
#6
for(int i=0;i<proid.length;i++)
{
String sql="update intidy set enum="+enum[i]+" where proid ='"+proid[i]+"'";
sta.executeUpdate(sql);
}
这样就有错,只要是传的数组就有错
如果传的是单独一条记录不是数组就没错
String sql="update intidy set enum="+enum+" where proid ='"+proid+"'";
sta.executeUpdate(sql);
我需要数组的,到底该怎么解决啊?
{
String sql="update intidy set enum="+enum[i]+" where proid ='"+proid[i]+"'";
sta.executeUpdate(sql);
}
这样就有错,只要是传的数组就有错
如果传的是单独一条记录不是数组就没错
String sql="update intidy set enum="+enum+" where proid ='"+proid+"'";
sta.executeUpdate(sql);
我需要数组的,到底该怎么解决啊?
#7
批量更新不是这么个更新法,要用addBatch
#8
空指针,说明你enum数组中的元素本来就有问题!!
还有enum字段是什么类型,varchar要加单引号的!
还有这根本就不叫批量更新,楼上说了批量更新的方法!!
还有enum字段是什么类型,varchar要加单引号的!
还有这根本就不叫批量更新,楼上说了批量更新的方法!!
#9
批量更新使用addBatch()与executeBatch()
#10
瀑布汗...
SQL语句你怎么用数组....
SQL语句你怎么用数组....
#11
他的代码
for(int i=0;i<proid.length;i++)
{
String sql="update TabDemo set enum="+enum[i]+" where proid ='"+proid[i]+"'";
sta.executeUpdate(sql);
}
就是不断变化参数嘛,这个就是可以用批量更新来做!
for(int i=0;i<proid.length;i++)
{
String sql="update TabDemo set enum="+enum[i]+" where proid ='"+proid[i]+"'";
sta.executeUpdate(sql);
}
就是不断变化参数嘛,这个就是可以用批量更新来做!
#12
应该这样写:
PreparedStatement sta = con.prepareStatement("update TabDemo set enum=? where proid =?");
for(int i=0;i<proid.length;i++)
{
sta.setString(1,enum[i]);
sta.setString(2,proid[i]);
sta.addBatch();
}
sta.executeBatch();
PreparedStatement sta = con.prepareStatement("update TabDemo set enum=? where proid =?");
for(int i=0;i<proid.length;i++)
{
sta.setString(1,enum[i]);
sta.setString(2,proid[i]);
sta.addBatch();
}
sta.executeBatch();
#13
Sunny319(努力学习java中.)
用
PreparedStatement sta = con.prepareStatement("update TabDemo set enum=? where proid =?");
for(int i=0;i<proid.length;i++)
{
sta.setString(1,enum[i]);
sta.setString(2,proid[i]);
sta.addBatch();
}
sta.executeBatch();
有错,报
H:\MPL\WEB-INF\classes\depots\SaveBean22.java:91: cannot resolve symbol
symbol : class PreparedStatement
location: class depots.SaveBean22
PreparedStatement sta = con.prepareStatement("update intidy set enum=? where proid =?");
^
1 error
Tool completed with exit code 1
我的问题怎么解决啊,我是菜鸟不懂的,谁帮忙解决啊,啊5555555
用
PreparedStatement sta = con.prepareStatement("update TabDemo set enum=? where proid =?");
for(int i=0;i<proid.length;i++)
{
sta.setString(1,enum[i]);
sta.setString(2,proid[i]);
sta.addBatch();
}
sta.executeBatch();
有错,报
H:\MPL\WEB-INF\classes\depots\SaveBean22.java:91: cannot resolve symbol
symbol : class PreparedStatement
location: class depots.SaveBean22
PreparedStatement sta = con.prepareStatement("update intidy set enum=? where proid =?");
^
1 error
Tool completed with exit code 1
我的问题怎么解决啊,我是菜鸟不懂的,谁帮忙解决啊,啊5555555
#14
我JDK是 j2sdk1.4.1_02 的
不会跟着有关吧???
不会跟着有关吧???
#15
import java.sql.PreparedStatement;
加上这个
加上这个
#16
没有引进包文件:
加载import java.sql.PreparedStatement;就可以了!
加载import java.sql.PreparedStatement;就可以了!
#17
批量更新
1、Statement
Statement sm = cn.createStatement();
sm.addBatch(sql1);
sm.addBatch(sql2);
...
sm.executeBatch()
一个Statement对象,可以执行多个sql语句以后,批量更新。这多个语句可以是delete、update、insert等或兼有
2、PreparedStatement
PreparedStatement ps = cn.preparedStatement(sql);
{
ps.setXXX(1,xxx);
...
ps.addBatch();
}
ps.executeBatch();
一个PreparedStatement,可以把一个sql语句,变换参数多次执行,一次更新。
1、Statement
Statement sm = cn.createStatement();
sm.addBatch(sql1);
sm.addBatch(sql2);
...
sm.executeBatch()
一个Statement对象,可以执行多个sql语句以后,批量更新。这多个语句可以是delete、update、insert等或兼有
2、PreparedStatement
PreparedStatement ps = cn.preparedStatement(sql);
{
ps.setXXX(1,xxx);
...
ps.addBatch();
}
ps.executeBatch();
一个PreparedStatement,可以把一个sql语句,变换参数多次执行,一次更新。
#18
try {
con = source.getConnection();
con.setAutoCommit(false);
con.setTransactionIsolation (Connection.TRANSACTION_SERIALIZABLE);
stmt = con.createStatement();
stmt.executeUpdate(updatesql);
con.commit();
}
} catch (Exception e) {
e.printStackTrace();
try {
con.rollback();
} catch (Exception ex) {
ex.printStackTrace();
}
} finally {
if (stmt != null) {
stmt.close();
}
if (con != null) {
con.close();
}
}
#19
我这个也是批量提交的