?!!!! 2021-08-10 09:32 采纳率: 33.3%
浏览 55
已结题

PrepareStatement部分的,运行时出错,希望可以帮我找找问题出在哪里


package com.zxy.zqk;

import com.zxy.zka.utils.JdbcUtils;

import java.sql.*;
import java.util.Date;

public class preparedStatementDemo {
    public static void main(String[] args) {
        Connection con = null;
        PreparedStatement st = null;
        ResultSet rs = null;
        try {
            con = JdbcUtils.getConnection();
            String sql = "INSERT INTO `users`(`id`,`NAME`,`PASSWORD`,`email`,`birthday`) VALUES(?,?,?,?,?)";
            st = con.prepareStatement(sql);
            st.setInt(1, 4);
            st.setString(2, "zhaoliu");
            st.setString(3, "123456");
            st.setString(4, "za@sina.com");
            st.setDate(5, new java.sql.Date(new Date().getTime()));
            int i = st.executeUpdate(sql);
            if (i > 0) {
                System.out.println("操作成功");
            }

        } catch (SQLException throwables) {
            throwables.printStackTrace();
        } finally {
            JdbcUtils.release(con, st, rs);
        }
    }
}

报错的内容:
Tue Aug 10 09:27:33 CST 2021 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
com.mysql.jdbc.exceptions.jdbc4.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 '?,?,?,?,?)' at line 1
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:403)
at com.mysql.jdbc.Util.getInstance(Util.java:386)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:944)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3933)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3869)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2524)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2675)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2465)
at com.mysql.jdbc.StatementImpl.executeUpdateInternal(StatementImpl.java:1536)
at com.mysql.jdbc.StatementImpl.executeLargeUpdate(StatementImpl.java:2585)
at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1464)
at com.zxy.zqk.preparedStatementDemo.main(preparedStatementDemo.java:22)

Process finished with exit code 0

  • 写回答

3条回答 默认 最新

  • a1767028198 2021-08-10 11:17
    关注

    executeUpdate(),别用executeUpdate(String sql),不然你前面那一堆set就没啥用处了

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

问题事件

  • 系统已结题 8月18日
  • 已采纳回答 8月10日
  • 创建了问题 8月10日

悬赏问题

  • ¥15 c++代码数据结构理解含义
  • ¥15 anaconda相关启动程序问题
  • ¥15 关于#hyperledger#的问题,如何解决?
  • ¥30 使用opencv中的solvePnPRansac计算相机位姿后,误差较大
  • ¥15 串口控制LED灯驱动板设计
  • ¥15 如何在unity场景里做到通过按钮实现模型替换
  • ¥15 uniapp的websocket和c++的websocket服务器通讯 发送的数据和接受的数据表现形式不一样
  • ¥15 pyspark配置中的错误
  • ¥15 html word表格
  • ¥15 kali安装包如何解决,请给明确方案和步骤