当前位置:网站首页>JDBC读取Mysql数据列表
JDBC读取Mysql数据列表
2022-06-27 06:55:00 【青云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 获取连接
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 ";
//3 获取执行sql的对象
Statement stmt = conn.createStatement();
//4 执行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 释放资源
stmt.close();
conn.close();
}
}
边栏推荐
- 2022 CISP-PTE(一)文件包含
- Write an example of goroutine and practice Chan at the same time
- Idea method template
- Matlab GUI interface simulation DC motor and AC motor speed simulation
- R 语言Analyzing wine data
- Window right click management
- Spark SQL common time functions
- Idea one click log generation
- YOLOv6又快又准的目标检测框架 已开源
- 面试官:你天天用 Lombok,说说它什么原理?我竟然答不上来…
猜你喜欢

DMU software syntax highlighting VIM setting -- Learning Notes 6

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

Fast realization of Bluetooth communication between MCU and mobile phone

Some settings about postfix completion code template in idea

MPC control of aircraft wingtip acceleration and control surface

Process termination (have you really learned recursion? Test your recursion Foundation)

Caldera installation and simple use

From 5 seconds to 1 second, the system flies

程序人生 - 程序员三十五岁瓶颈你怎么看?

Centos7.9安装mysql 5.7,并设置开机启动
随机推荐
SQL 注入绕过(一)
winow10安装Nexus nexus-3.20.1-01
jupyter notebook文件目录
tracepoint
Window right click management
再见了,敏捷Scrum
R 语言并行计算 spearman 相关系数,加快共现网络(co- occurrence network)构建速度
R 语言Analyzing wine data
2022 le fichier CISP - Pte (i) contient:
Delay queue `delayqueue`
Mathematical modeling contest for graduate students - optimal application of UAV in rescue and disaster relief
Date database date strings are converted to and from each other
Meaning of 0.0.0.0:x
pytorch Default process group is not initialized
请问网页按钮怎么绑定sql语句呀
guava 教程收集一些案例慢慢写 google工具类
Thesis reading skills
多表联查--07--- Hash join
Yolov6's fast and accurate target detection framework is open source
Classical cryptosystem -- substitution and replacement