当前位置:网站首页>Mr. Sun's version of JDBC (21:34:25, June 12, 2022)
Mr. Sun's version of JDBC (21:34:25, June 12, 2022)
2022-06-12 21:53:00 【Red eye Aromatherapy】
Database auto shutdown , It's much more convenient .
package com.item.dao;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
public class JDBCUtil implements AutoCloseable {
private static String driver="com.mysql.jdbc.Driver";
private static String url="jdbc:mysql://127.0.0.1:3306/mytest?characterEncoding=utf-8";
// Connection object
private static Connection conn;
// Result set
private static ResultSet rs;
// Code block
static{
try {
Class.forName(driver);
conn = DriverManager.getConnection(url, "root", "12345678");
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* whole SQL Inquire about
* @param sql
* @return
* @throws SQLException
*/
public static ResultSet query(String sql) throws SQLException {
return conn.createStatement().executeQuery(sql);
}
/**
* @param sql
* @return
* @throws SQLException
*/
public static int update(String sql) throws SQLException {
return conn.prepareStatement(sql).executeUpdate();
}
@Override
public void close() throws Exception {
if (null != rs) {
rs.close();
}
if (null != conn) {
conn.close();
}
}
}The test data :
public static void main(String[] args) throws SQLException {
ResultSet re = query("select * from users");
while (re.next()) {
System.out.println(re.getObject(1));
System.out.println(re.getObject(2));
System.out.println(re.getObject(3));
System.out.println(re.getObject(4));
System.out.println(re.getObject(5));
}
}
swing
/**
* Convert to Vectors aggregate
*
* @param userList
* @return
*/
public static Vector<Vector<String>> listToVectors(List<UserVo> userList) {
Vector<Vector<String>> datas = new Vector<Vector<String>>();
for (int i = 0; i < userList.size(); i++) {
UserVo u = userList.get(i);
if (null == u)
continue;
Vector<String> item = new Vector<String>();
item.add(u.getId().toString());
item.add(u.getAccount());
item.add(u.getSex() == 1 ? " male " : " Woman ");
item.add(u.getEducation());
item.add(u.getPhone());
item.add(u.getEmail());
item.add(u.getRegisterDate());
if (null == u.getUpdateDate()) {
item.add("");
}else {
item.add(u.getUpdateDate());
}
datas.add(item);
}
return datas;
}Three line implementation JTable Data update .
datas.clear();
datas.addAll(ListDbUtils.listToVectors(userService.list()));
jTable.updateUI();
JTable jTable = new JTable(datas, heads);This is more convenient and faster , however javaEE Has not been tested yet . I'll get a complete one later .
边栏推荐
- SQL调优指南笔记10:Optimizer Statistics Concepts
- 【QNX Hypervisor 2.2 用户手册】4.3 获取host组件
- Oracle 19C installation documentation
- OceanBase 社区版 OCP 功能解读
- Ansible playbook and variable (II)
- Oracle livelabs experiment: introduction to Oracle Spatial
- MySQL介绍和安装(一)
- How to implement a simple publish subscribe mode
- KDD2022 | GraphMAE:自监督掩码图自编码器
- What is the difference between volatile variables and atomic variables?
猜你喜欢

Ansible PlayBook et ansible roles (3)

MySQL introduction and installation (I)

SQL tuning guide notes 14:managing extended statistics

最近公共祖先问题你真的学会了吗?

孙老师版本JDBC(2022年6月12日21:34:25)

User guide for JUC concurrency Toolkit

SQL tuning guide notes 13:gathering optimizer statistics

Graphics2d class basic use

Ansible playbook和变量(二)

ICML2022 | GALAXY:極化圖主動學習
随机推荐
Yyds dry goods inventory solution sword finger offer: the first non repeated character in the character stream
What is your understanding of thread priority?
ICML2022 | GALAXY:极化图主动学习
MySQL介绍和安装(一)
Ansible summary (VI)
DRF receives nested data and creates objects. Solution: DRF not NULL constraint failed
建立高可用的数据库
Ansible playbook and variable (II)
SQL调优指南笔记10:Optimizer Statistics Concepts
Xingda easy control ModbusRTU to modbustcp gateway
The ifeq, filter and strip of makefile are easy to use
Ansible roles project case (IV)
Lambda expression and flow optimization code
“Oracle数据库并行执行”技术白皮书读书笔记
Oracle LiveLabs实验:Introduction to Oracle Spatial Studio
SQL调优指南笔记15:Controlling the Use of Optimizer Statistics
JVisualVM初步使用
SQL调优指南笔记12:Configuring Options for Optimizer Statistics Gathering
June training (day 11) - matrix
Graphics2D类基本使用