当前位置:网站首页>JDBC parameterized query example
JDBC parameterized query example
2022-06-27 07:21:00 【Qingyun ing】
import com.mysql.jdbc.Driver;
import java.sql.*;
public class JDBCDemo {
public static void main(String[] args) throws Exception {
//1 Get the connection
String url = "jdbc:mysql://IP:Port/db_name";
String username = "username ";
String password = "password ";
Connection conn = DriverManager.getConnection(url, username, password);
//2 sql sentence
String sql = "select * from account where name=?";
//3 Access to perform sql The object of
PreparedStatement stmt = conn.prepareStatement(sql);
stmt.setString(1, " Qingyun ing");
//4 perform sql
ResultSet rs = stmt.executeQuery();
while (rs.next()) {
System.out.println("-----------------");
System.out.println("ID:" + rs.getInt("id") + " Name:" + rs.getString("name") + " Age:" + rs.getInt("age"));
}
//6 Release resources
stmt.close();
conn.close();
}
}
边栏推荐
- 2022 cisp-pte (II) SQL injection
- ggplot2的自定义调色板
- 使用 Blackbox Exporter 测试网络连通性
- Basic SQL operations in tidb
- winow10安装Nexus nexus-3.20.1-01
- 进程终止(你真的学会递归了吗?考验你的递归基础)
- Configuring FTP, enterprise official website, database and other methods for ECS
- Installation and functions of uview
- guava 教程收集一些案例慢慢写 google工具类
- 获取地址url中的query参数指定参数方法
猜你喜欢

YOLOv6又快又准的目标检测框架 已开源

2022 cisp-pte (II) SQL injection

Xiaomi Interviewer: let's talk about the proficient Registration Center for three days and three nights

How to download opencv? How to configure opencv after downloading?

2022 CISP-PTE(一)文件包含

Configuring FTP, enterprise official website, database and other methods for ECS

POI replacing text and pictures in docx

yarn create vite 报错 ‘D:\Program‘ 不是内部或外部命令,也不是可运行的程序 或批处理文件

2022 CISP-PTE(一)文件包含

【Kevin三连弹之三】Rust真的比C慢吗?进一步分析queen微测评
随机推荐
请问网页按钮怎么绑定sql语句呀
When there are multiple El select, the selected value is filtered by El select, and the last selected value is filtered by the second El select
2022 CISP-PTE(一)文件包含
Goodbye, agile Scrum
VNC Viewer方式的远程连接树莓派
Hutool symmetric encryption
2022 CISP-PTE(一)文件包含
volatile 和 synchronized 到底啥区别?
Modeling competition - optical transport network modeling and value evaluation
2022 cisp-pte (II) SQL injection
sql sever列名或所提供值的数目与表定义不匹配
oracle的similarity方法实现原理
mysql关于自增和不能为空
How to download opencv? How to configure opencv after downloading?
【毕业季】毕业是人生旅途的新开始,你准备好了吗
Manim math engine
攻防演习防御体系构建之第二篇之应对攻击的常用策略
Bean拷贝详解
View functions in tidb
【Kevin三连弹之三】Rust真的比C慢吗?进一步分析queen微测评