在 MySQL 中保存 3gp 文件时出现 ArrayIndexOutOfBoundsException
我的代码是:
psmnt = conn.prepareStatement("INSERT INTO upload_data(user_id,photo,audio) " + "values(?,?)");
psmnt.setLong(1, userId);
fis = new FileInputStream(photoFile);
psmnt.setBinaryStream(2, (InputStream) fis, (int) (photoFile.length()));
fisAudio = new FileInputStream(audioFile);
psmnt.setBinaryStream(3, (InputStream) fisAudio, (int) (audioFile.length()));
int s = psmnt.executeUpdate();
MySQL数据库中的音频类型是blob。
例外的是:
java.lang.ArrayIndexOutOfBoundsException: 2
at com.mysql.jdbc.PreparedStatement.setBinaryStream(PreparedStatement.java:2089)
at com.test.dao.TestDao.saveTestDetails1(TestDAo.java:154)
at com.test.servlet.UploadImage.doPost(UploadImage.java:131)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
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:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Unknown Source)
如何解决这个问题?
My code is:
psmnt = conn.prepareStatement("INSERT INTO upload_data(user_id,photo,audio) " + "values(?,?)");
psmnt.setLong(1, userId);
fis = new FileInputStream(photoFile);
psmnt.setBinaryStream(2, (InputStream) fis, (int) (photoFile.length()));
fisAudio = new FileInputStream(audioFile);
psmnt.setBinaryStream(3, (InputStream) fisAudio, (int) (audioFile.length()));
int s = psmnt.executeUpdate();
The type of audio in the MySQL database is a blob.
Exception is:
java.lang.ArrayIndexOutOfBoundsException: 2
at com.mysql.jdbc.PreparedStatement.setBinaryStream(PreparedStatement.java:2089)
at com.test.dao.TestDao.saveTestDetails1(TestDAo.java:154)
at com.test.servlet.UploadImage.doPost(UploadImage.java:131)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
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:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Unknown Source)
How to resolve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
psmnt.setBinaryStream(3,
Jennifer,您正在尝试设置第三个参数,但插入中只有两个参数:
psmnt.setBinaryStream(3,
Jennifer, you're trying to set the third parameter but you only have two in your insert:
你的 SQL 语句中只有两个参数(问号),但你试图将二进制流绑定到第三个参数,而不是现有的参数。像这样更改你的 SQL 语句:
you have only two parameters (question marks) in your SQL statement, but you're trying to bind the binary stream to the 3rd, not existing one. change your SQL statement like this: