当前位置:网站首页>报错问题Parameter index out of range(0 < 1) (1 > number of parameters,which is 0
报错问题Parameter index out of range(0 < 1) (1 > number of parameters,which is 0
2022-06-26 06:55:00 【左海峰博客】
jdbc连接数据库
public class DbUtil {
static{
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
public static Connection getConnection(){
String url = "jdbc:mysql://127.0.0.1:3306/test?serverTimezone=GMT%2B8";
String account = "root";
String pwd = "root";
Connection connection = null;
try {
connection = DriverManager.getConnection(url,account,pwd);
} catch (SQLException e) {
e.printStackTrace();
}
return connection;
}使用Db.Util工具类插入数据的两种方法。
String sql = "insert into student(name,phone) values (?,?)";
PreparedStatement ps = connection.prepareStatement(sql);
ps.setString(1,firstname);
ps.setString(2,lastname);
ps.executeUpdate();占位。setString表示第几个占位符。从1开始。
或者采用直接sql拼接。
String sql = "insert into student(name,phone) values('"+firstname+"','"+lastname+"')";
PreparedStatement ps = connection.prepareStatement(sql);
ps.executeUpdate();setString可能会报的两个错误。
Parameter index out of range(0 < 1) 代表索引从1开始。
Parameter index out of range(1 > number of parameters,which is 0) 代表找不到占位符就是那个 ?号。
下面这个错记得加
![]()

边栏推荐
- STM32F1与STM32CubeIDE编程实例-热敏传感器驱动
- Past events of Xinhua III
- How to make the main thread wait for the sub thread to execute before executing
- Format one insert per line using mysqldump- Using mysqldump to format one insert per line?
- DS18B20 details
- 同花顺究竟如何开户,网上开户是否安全么?
- Solution of garbled code in sparkshell deletion key of SecureCRT
- How to choose securities companies for stock speculation? Is it safe to open a mobile account?
- Laravel implements groupby to query the number of packets
- [004] [stm32] MDK project configuration and commissioning
猜你喜欢

Live broadcast Preview - fire safety instructor training "cloud class" is about to start!

DS18B20 details

【图像检测】基于Itti模型实现图像显著性检测附matlab代码

海量日志采集工具——Flume

SecureCRT运行SparkShell 删除键出现乱码的解法

Reasons why MySQL indexes are not effective
![[micro service series] protocol buffer dynamic analysis](/img/86/357d55c77cc67d6413af2de59bf395.png)
[micro service series] protocol buffer dynamic analysis

数据挖掘是什么?

在公司逮到一个阿里10年的测试开发,聊过之后大彻大悟...

What is data mining?
随机推荐
一芯实现喷雾|WS2812驱动|按键触摸|LED显示|语音播报芯片等功能,简化加湿器产品设计
SHOW语句用法补充
MATLAB线性规划模型学习笔记
闭包问题C# Lua
[golang] time related
Phantom star VR equipment product details II: dark battlefield
“试用期避免被辞退“ 指南攻略
web入门之 Promise API
Usage of zip (*arg)
C# Nuget离线缓存包安装
shell 输入验证仅限字母数字
Lightgbm-- parameter adjustment notes
China polyimide film market demand and future investment risk outlook report 2022-2027
炒股怎么选择证券公司?手机开户安全么?
Professional course - Code question record
Invalid problem of self defined map used by Gaode map
Decompile Android applications, interview Android
【图像融合】基于梯度能量、局部能量、 PCA三种融合规则实现MRI-CT图像融合附matlab代码
Easyar use of unity
js-下载图片