当前位置:网站首页>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 .
边栏推荐
- jsonUtils
- Ansible summary (VI)
- SQL tuning guide notes 9:joins
- 有向图深拷贝
- The ifeq, filter and strip of makefile are easy to use
- 图灵奖得主:想要在学术生涯中获得成功,需要注意哪些问题?
- How to ensure thread safety?
- PCB封装下载网站推荐及其详细使用方法
- 同花顺能开户吗,在APP上可以直接开通券商安全吗 ,证券开户怎么开户流程
- How do complex systems detect anomalies? North Carolina UNCC and others' latest overview of graph based deep learning anomaly detection methods in complex distributed systems describes the latest prog
猜你喜欢

PE安装win10系统

SQL tuning guide notes 8:optimizer access paths

KDD2022 | GraphMAE:自监督掩码图自编码器

A puzzle about + =

Deep Hough voting for 3D object detection in point clouds

Icml2022 | Galaxy: apprentissage actif des cartes de polarisation

Ansible playbook and variable (II)

SQL调优指南笔记14:Managing Extended Statistics

User guide for JUC concurrency Toolkit

MySQL introduction and installation (I)
随机推荐
SQL调优指南笔记11:Histograms
SQL调优指南笔记9:Joins
Have you really learned the common ancestor problem recently?
[simple] 155 Minimum stack
ORM implements the mapping relationship between classes and tables, class attributes and fields
Data batch writing
在同花顺开户证券安全吗,证券开户怎么开户流程
Zip compression decompression
How to develop programming learning with zero foundation during college
Turing prize winner: what should I pay attention to if I want to succeed in my academic career?
多线程模型下的生产者消费者模式
Oracle SQL Developer的代码输入框中推荐使用的中文字体
Npoi create word
Digraph deep copy
ICML2022 | GALAXY:極化圖主動學習
MySQL master-slave replication
Libmysqlclient A static library
Design and practice of Hudi bucket index in byte skipping
Open source background management system suitable for outsourcing projects
【QNX Hypervisor 2.2 用戶手册】4.2 支持的構建環境