当前位置:网站首页>JDBC reads MySQL data list
JDBC reads MySQL data list
2022-06-27 07:21:00 【Qingyun ing】
import com.mysql.jdbc.Driver;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
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 ";
//3 Access to perform sql The object of
Statement stmt = conn.createStatement();
//4 perform sql
ResultSet rs = stmt.executeQuery(sql);
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();
}
}
边栏推荐
- Vs how to configure opencv? 2022vs configuration opencv details (multiple pictures)
- Fractional Order PID control
- [graduation season] graduation is the new beginning of your life journey. Are you ready
- 一个人管理1000台服务器?这款自动化运维工具一定要掌握
- 2022 CISP-PTE(二)SQL注入
- Interviewer: do you have any plan to request a lot of data that does not exist in redis to destroy the database?
- HTAP in depth exploration Guide
- 面试官:请你介绍一下缓存穿透、缓存空值、缓存雪崩、缓存击穿的,通俗易懂
- JDBC操作Mysql示例
- 进程终止(你真的学会递归了吗?考验你的递归基础)
猜你喜欢
One person manages 1000 servers? This automatic operation and maintenance tool must be mastered
vs怎么配置OpenCV?2022vs配置OpenCV详解(多图)
Interviewer: please introduce cache penetration, cache null value, cache avalanche and cache breakdown, which are easy to understand
Classical cryptosystem -- substitution and replacement
进程终止(你真的学会递归了吗?考验你的递归基础)
[graduation season] graduation is the new beginning of your life journey. Are you ready
Memory barrier store buffer, invalid queue
Redis cache penetration, cache breakdown, cache avalanche
使用 Blackbox Exporter 测试网络连通性
SQL injection bypass (I)
随机推荐
One person manages 1000 servers? This automatic operation and maintenance tool must be mastered
pytorch Default process group is not initialized
Park and unpark in unsafe
The interviewer of a large front-line factory asked: do you really understand e-commerce order development?
OPPO面试整理,真正的八股文,狂虐面试官
2022 cisp-pte (II) SQL injection
将通讯录功能设置为数据库维护,增加用户名和密码
Currying Scala functions
Winow10 installation nexus nexus-3.20.1-01
Difference between boundvalueops and opsforvalue
请问网页按钮怎么绑定sql语句呀
Solve the problem of win10 wsl2 IP change
Interviewer: do you have any plan to request a lot of data that does not exist in redis to destroy the database?
Idea method template
2022 le fichier CISP - Pte (i) contient:
程序人生 - 程序员三十五岁瓶颈你怎么看?
Hutool symmetric encryption
Talk about Domain Driven Design
mysql关于自增和不能为空
Guava scheduled task