当前位置:网站首页>How to solve the code error when storing array data into the database
How to solve the code error when storing array data into the database
2022-07-02 03:49:00 【CSDN Q & A】
How to solve the error of this code ?
import java.sql.Connection;import java.sql.DriverManager;//import java.sql.Statement;import java.util.ArrayList;import java.util.List;import java.sql.PreparedStatement;import java.sql.PseudoColumnUsage;//import java.sql.SQLException;class sql1{ int id; String name; int age; public sql1(int id, String name, int age) { super(); this.id=id; this.name=name; this.age=age; } @Override public String toString() { return "id=" + id + ", name=" + name + ", age=" + age ; }}public class ASDZ { public static void main(String[] args) throws Exception { // TODO Auto-generated method stub List<sql1> yu=new ArrayList<>(); yu.add(new sql1(23,"ykg",12)); yu.add(new sql1(24,"ykg1",14)); yu.add(new sql1(25,"ykg2",17));// for(sql1 i:yu) {// System.out.println(i.toString());// } Class.forName("com.mysql.jdbc.Driver"); Connection con=null; //Statement stmt=null; PreparedStatement ps=null; con=DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/ykg?useSSL=false","root","03579631"); //stmt= con.createStatement(); String sql="insert into yu values(?,?,?)"; ps=con.prepareStatement(sql); for(int i=0;i<yu.size();i++) { ps.setInt(1, yu.get(i).id); ps.setString(2, yu.get(i).name); ps.setInt(3, yu.get(i).age); ps.executeUpdate(sql); //Update } if(ps!=null) ps.close(); if(con!=null) con.close(); }}Operation results and error reporting contents
Exception in thread "main" 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 java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:78)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
at com.mysql.jdbc.Util.getInstance(Util.java:408)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:944)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3978)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3914)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2530)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2683)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2491)
at com.mysql.jdbc.StatementImpl.executeUpdateInternal(StatementImpl.java:1552)
at com.mysql.jdbc.StatementImpl.executeLargeUpdate(StatementImpl.java:2607)
at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1480)
at ASDZ.main(ASDZ.java:46)
边栏推荐
- Blue Bridge Cup single chip microcomputer sixth temperature recorder
- 《西线无战事》我们才刚开始热爱生活,却不得不对一切开炮
- Kubernetes cluster storageclass persistent storage resource core concept and use
- Imageai installation
- Review materials of project management PMP high frequency examination sites (8-1)
- Xlwings drawing
- In the era of programmers' introspection, five-year-old programmers are afraid to go out for interviews
- The first practical project of software tester: web side (video tutorial + document + use case library)
- 跳出舒适区,5年点工转型自动化测试工程师,我只用了3个月时间
- 蓝桥杯单片机省赛第六届
猜你喜欢

The second game of the 12th provincial single chip microcomputer competition of the Blue Bridge Cup

The 10th Blue Bridge Cup single chip microcomputer provincial competition

High performance and low power cortex-a53 core board | i.mx8m Mini

跳出舒适区,5年点工转型自动化测试工程师,我只用了3个月时间

The 6th Blue Bridge Cup single chip microcomputer provincial competition

WPViewPDF Delphi 和 .NET 的 PDF 查看组件

Getting started with MQ

The first game of the 12th Blue Bridge Cup single chip microcomputer provincial competition

It took me only 3 months to jump out of the comfort zone and become an automated test engineer for 5 years
![[Li Kou brush questions] 15 Sum of three numbers (double pointer); 17. Letter combination of phone number (recursive backtracking)](/img/5e/81e613370c808c63665c14298f9a39.png)
[Li Kou brush questions] 15 Sum of three numbers (double pointer); 17. Letter combination of phone number (recursive backtracking)
随机推荐
VS2010插件NuGet
【IBDFE】基于IBDFE的频域均衡matlab仿真
蓝桥杯单片机省赛第十一届第二场
《MATLAB 神經網絡43個案例分析》:第42章 並行運算與神經網絡——基於CPU/GPU的並行神經網絡運算
Network connection mode of QT
Unity脚本的基础语法(6)-特定文件夹
初识string+简单用法(二)
Suggestions on settlement solution of u standard contract position explosion
蓝桥杯单片机省赛第十届
The second game of the 12th provincial single chip microcomputer competition of the Blue Bridge Cup
[designmode] builder model
Oracle common SQL
近段时间天气暴热,所以采集北上广深去年天气数据,制作可视化图看下
蓝桥杯单片机第六届温度记录器
蓝桥杯单片机省赛第七届
潘多拉 IOT 开发板学习(HAL 库)—— 实验2 蜂鸣器实验(学习笔记)
Fourier series
How to do medium and long-term stocks, and what are the medium and long-term stock trading skills?
Cloud service selection of enterprises: comparative analysis of SaaS, PAAS and IAAs
High performance and low power cortex-a53 core board | i.mx8m Mini