当前位置:网站首页>JDBC参数化查询示例
JDBC参数化查询示例
2022-06-27 06:55:00 【青云ing】
import com.mysql.jdbc.Driver;
import java.sql.*;
public class JDBCDemo {
public static void main(String[] args) throws Exception {
//1 获取连接
String url = "jdbc:mysql://IP:Port/db_name";
String username = "username ";
String password = "password ";
Connection conn = DriverManager.getConnection(url, username, password);
//2 sql 语句
String sql = "select * from account where name=?";
//3 获取执行sql的对象
PreparedStatement stmt = conn.prepareStatement(sql);
stmt.setString(1, "青云ing");
//4 执行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 释放资源
stmt.close();
conn.close();
}
}
边栏推荐
- [openairinterface5g] rrcsetupcomplete for RRC NR resolution
- Fractional Order PID control
- 【OpenAirInterface5g】RRC NR解析之RrcSetupComplete
- The interviewer of a large front-line factory asked: do you really understand e-commerce order development?
- Talk about Domain Driven Design
- poi导出excle
- mssql如何使用语句导出并删除多表数据
- Restrictions on the use of tidb
- 一线大厂面试官问:你真的懂电商订单开发吗?
- 2018 mathematical modeling competition - special clothing design for high temperature operation
猜你喜欢

面试官:大量请求 Redis 不存在的数据,从而打倒数据库,你有什么方案?

Fast realization of Bluetooth communication between MCU and mobile phone

Caldera installation and simple use

SQL injection bypass (I)

Currying Scala functions

Classical cryptosystem -- substitution and replacement

Meaning of 0.0.0.0:x

POI replacing text and pictures in docx

Oppo interview sorting, real eight part essay, abusing the interviewer

thrift
随机推荐
正斜杠反斜杠的由来
guava 定时任务
Bean拷贝详解
用XGBoost迭代读取数据集
tracepoint
manim 数学引擎
Easyexcel: read Excel data into the list set
多表联查--07--- Hash join
OPPO面试整理,真正的八股文,狂虐面试官
Spark SQL common time functions
Modeling competition - optical transport network modeling and value evaluation
Vs how to configure opencv? 2022vs configuration opencv details (multiple pictures)
[openairinterface5g] rrcsetupcomplete for RRC NR resolution
高薪程序员&面试题精讲系列116之Redis缓存如何实现?怎么发现热key?缓存时可能存在哪些问题?
2022 CISP-PTE(一)文件包含
Difference between boundvalueops and opsforvalue
Tidb database Quick Start Guide
Currying Scala functions
Unrecognized VM option ‘‘
面试官:你天天用 Lombok,说说它什么原理?我竟然答不上来…