当前位置:网站首页>报错问题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) 代表找不到占位符就是那个 ?号。
下面这个错记得加
![]()

边栏推荐
- If you meet a female driver who drives didi as an amateur, you can earn 500 yuan a day!
- MySQL 数据库的小白安装与登录
- Past events of Xinhua III
- Simple use of enum type in TS
- 【特征提取】基于稀疏PCA实现目标识别信息特征选择附matlab源码
- Usage of zip (*arg)
- Go learning notes 1.3- data types of variables
- Development trends and prospects of acrylamide crystallization market in the world and China 2022-2027
- How to choose securities companies for stock speculation? Is it safe to open a mobile account?
- Format one insert per line using mysqldump- Using mysqldump to format one insert per line?
猜你喜欢

unity之EasyAR使用

【元胞自动机】基于元胞自动机实现高速公路收费站交通流问题附matlab代码

MySQL基础用法01

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

Professional course - Code question record

Paths with a certain value in a binary tree (1) (2) (3) (Sword finger offer)

C nuget offline cache package installation
![[004] [stm32] MDK project configuration and commissioning](/img/a8/9817cdbbce557a92739de494490706.jpg)
[004] [stm32] MDK project configuration and commissioning

Temperature alarm

I caught a 10-year-old Alibaba test developer in the company. After chatting with him, I realized everything
随机推荐
Open source demo| you draw and I guess -- make your life more interesting
宝塔服务器搭建及数据库远程连接
Distribution operation of D
【图像融合】基于梯度能量、局部能量、 PCA三种融合规则实现MRI-CT图像融合附matlab代码
China polyphenylene oxide Market Development Prospect and Investment Strategy Research Report 2022-2027
Temperature alarm
营销技巧:相比较讲产品的优点,更有效的是要向客户展示使用效果
PyTorch搭建CNN-LSTM混合模型实现多变量多步长时间序列预测(负荷预测)
Jasminum plug-in of Zotero document management tool
【图像检测】基于形态学实现图像目标尺寸测量系统附matlab代码
分析 NFT 项目的 5 个指标
DS18B20 details
LabVIEW arduino TCP / IP Remote Intelligent Home System (Project section - 5)
Fmt Must the result of println (true) be true?
【图像检测】基于Itti模型实现图像显著性检测附matlab代码
China polyimide film market demand and future investment risk outlook report 2022-2027
解决dialog 底部透明的问题
I use flask to write the website "II"
Go learning notes 1.3- data types of variables
[path planning] robot path planning based on improved artificial potential field with matlab code