mysql 高版本jdbc驱动程序使用PreparedStatement.setBinaryStream方法报错及解决办法

mysql 高于版本jdbc驱动程序 使用PreparedStatement.setBinaryStream方法报错及解决办法。

mysql 使用以下版本驱动程序 在PreparedStatement中执行setBinaryStream方法时报错误:
mysql-connector-java-5.0.8-bin.jar
mysql-connector-java-5.1.13-bin.jar

错误信息如下:

com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '? ?±n????#??1}?M????\'dG???zPd m7??‘*4??@?8ê§??à????‘6m?-?
E?OH??A?—6tl?iq?' at line 1
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1051)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3566)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3498)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1959)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2113)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2568)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2113)
at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1364)
at com.frameworkset.commons.dbcp.DelegatingPreparedStatement.execute(DelegatingPreparedStatement.java:169)
at com.frameworkset.common.poolman.PreparedDBUtil.innerExecute(PreparedDBUtil.java:1223)
at com.frameworkset.common.poolman.PreparedDBUtil.executePrepared(PreparedDBUtil.java:1578)
at com.frameworkset.common.poolman.PreparedDBUtil.executePrepared(PreparedDBUtil.java:924)
at com.frameworkset.mysql.mysql.testBlobWrite(mysql.java:157)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:44)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:180)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:41)
at org.junit.runners.ParentRunner$1.evaluate(ParentRunner.java:173)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
at org.junit.runners.ParentRunner.run(ParentRunner.java:220)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)


可以使用版本mysql-connector-java-3.1.14-bin.jar,执行就不报错。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
首先,您需要连接到 MySQL 数据库,可以使用 JDBC (Java Database Connectivity) 来实现。 下面是一个简单的示例,展示了如何使用 JDBC 连接到 MySQL 数据库: ``` import java.sql.*; public class MySQLConnectExample { public static void main(String[] args) { Connection connection = null; try { // 加载 MySQL 驱动程序 Class.forName("com.mysql.cj.jdbc.Driver"); // 连接到数据库 connection = DriverManager.getConnection( "jdbc:mysql://localhost:3306/database_name", "username", "password"); } catch (ClassNotFoundException e) { System.out.println("MySQL 驱动程序未找到!"); e.printStackTrace(); return; } catch (SQLException e) { System.out.println("数据库连接失败!"); e.printStackTrace(); return; } // 如果连接成功,则会到达这里 System.out.println("数据库连接成功!"); } } ``` 在连接到数据库后,您可以使用 SQL 语句将图像数据插入到数据库。 例如,您可以使用以下语句将图像文件上传到数据库: ``` PreparedStatement statement = connection.prepareStatement("INSERT INTO images (image) VALUES (?)"); FileInputStream inputStream = new FileInputStream("image.jpg"); statement.setBinaryStream(1, inputStream); statement.executeUpdate(); ``` 在这里,我们使用 `PreparedStatement` 来执行带有二进制数据的 `INSERT` 语句。 我们使用 `FileInputStream` 读取图像文件,然后将其设置为 `Prepared Statement` 的参数,并使用 `executeUpdate` 方法执行语句。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值