当前位置:网站首页>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();
}
}
边栏推荐
- Nature、science、cell旗下刊物
- Tidb basic functions
- JDBC读取Mysql数据列表
- Interviewer: how to never migrate data and avoid hot issues by using sub database and sub table?
- Apifox learning
- DMU software syntax highlighting VIM setting -- Learning Notes 6
- 聊聊领域驱动设计
- 高薪程序员&面试题精讲系列116之Redis缓存如何实现?怎么发现热key?缓存时可能存在哪些问题?
- IDEA连接数据库报错
- POI replacing text and pictures in docx
猜你喜欢

一个人管理1000台服务器?这款自动化运维工具一定要掌握

mssql如何使用语句导出并删除多表数据

面试官:用分库分表如何做到永不迁移数据和避免热点问题?

用XGBoost迭代读取数据集

vs怎么配置OpenCV?2022vs配置OpenCV详解(多图)

Modeling competition - optical transport network modeling and value evaluation

2022 cisp-pte (II) SQL injection

【软件工程】山东大学软件工程复习提纲

volatile 和 synchronized 到底啥区别?

面试官:你天天用 Lombok,说说它什么原理?我竟然答不上来…
随机推荐
Mathematical modeling contest for graduate students - optimal application of UAV in rescue and disaster relief
Matlab GUI interface simulation DC motor and AC motor speed simulation
IDEA连接数据库报错
Idea method template
面试官:你天天用 Lombok,说说它什么原理?我竟然答不上来…
2022 CISP-PTE(一)文件包含
VNC Viewer方式的远程连接树莓派
Talk about Domain Driven Design
Nature、science、cell旗下刊物
Bean拷贝详解
thrift
manim 数学引擎
NoViableAltException([email protected][2389:1: columnNameTypeOrConstraint : ( ( tableConstraint ) | ( columnNameT
SQL injection bypass (I)
Vs how to configure opencv? 2022vs configuration opencv details (multiple pictures)
pytorch Default process group is not initialized
MPC control of aircraft wingtip acceleration and control surface
如何优雅的写 Controller 层代码?
Gérer 1000 serveurs par personne? Cet outil d'automatisation o & M doit être maîtrisé
一线大厂面试官问:你真的懂电商订单开发吗?