当前位置:网站首页>JDBC connection database
JDBC connection database
2022-04-23 06:00:00 【hanyc..】
Main steps :
1、 Load database driver
2、 Get database connection ( It includes getting user information 、url)
3、 Create execution sql The object of
4、 perform sql sentence
5、 Returns the result set of the execution
6、 Release the connection
package com.hyc.study01;
import java.sql.*;
public class JdbcFirstDemo {
public static void main(String[] args) throws ClassNotFoundException, SQLException {
//1、 Load database driver
Class.forName("com.mysql.jdbc.Driver");
//2、 Get user information 、url
//jdbcstudy Is the name of the database to connect to
//useUnicode=true&characterEncoding=utf8&useSSL=true Support Chinese coding & Set the Chinese character set to utf8& Using secure connections
String url =
"jdbc:mysql://localhost:3306/jdbcstudy?useUnicode=true&characterEncoding=utf8&useSSL=true";
String username = "root";
String psw = "123456";
//3、 Get database connection
// there Connection It represents the database , If the returned object is not empty , On behalf of the database, you get
Connection connection = DriverManager.getConnection(url, username, psw);
//4、 Created to perform sql The object of
Statement statement = connection.createStatement();
//5、 perform sql sentence
//6、 Return execution result set
String sql = "SELECT * FROM users";
// Execute the query sql sentence , Get the returned result set
ResultSet resultSet = statement.executeQuery(sql);// The returned result set is in the form of a linked list
while (resultSet.next()) {
System.out.println("id=" + resultSet.getInt("id"));
System.out.println("name=" + resultSet.getString("NAME"));
System.out.println("psw=" + resultSet.getString("PASSWORD"));
System.out.println("email=" + resultSet.getString("email"));
System.out.println("birth=" + resultSet.getDate("birthday"));
System.out.println("=====================================================");
}
//int num = statement.executeUpdate("add delete update sql");
// All additions, deletions and modifications are used statement.executeUpdate(), This method returns the execution sql The number of lines affected by the statement
//7、 Release the connection
resultSet.close();
statement.close();
connection.close();
}
}
Database and database tables :
版权声明
本文为[hanyc..]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230541160359.html
边栏推荐
- Rsync for file server backup
- 数据处理之Numpy常用函数表格整理
- Pytorch学习记录(九):Pytorch中卷积神经网络
- 域内用户访问域外samba服务器用户名密码错误
- Anaconda
- K/3 WISE系统考勤客户端日期只能选到2019年问题
- MySql基础狂神说
- Latex quick start
- Paper on LDCT image reconstruction: edge enhancement based transformer for medical image denoising
- 常用编程记录——parser = argparse.ArgumentParser()
猜你喜欢
Filebrowser realizes private network disk
对比学习论文——[MoCo,CVPR2020]Momentum Contrast for Unsupervised Visual Representation Learning
域内用户访问域外samba服务器用户名密码错误
On traversal of binary tree
Ptorch learning record (XIII): recurrent neural network
图像恢复论文——[RED-Net, NIPS16]Image Restoration Using Very Deep Convolutional Encoder-Decoder Networks wi
Practical operation - Nacos installation and configuration
Pytorch学习记录(七):处理数据和训练模型的技巧
Fundamentals of in-depth learning -- a simple understanding of meta learning (from Li Hongyi's course notes)
关于二叉树的遍历
随机推荐
ValueError: loaded state dict contains a parameter group that doesn‘t match the size of optimizer‘s
Fundamentals of digital image processing (Gonzalez) II: gray transformation and spatial filtering
Pytoch learning record (x): data preprocessing + batch normalization (BN)
Create enterprise mailbox account command
JVM series (3) -- memory allocation and recycling strategy
无监督去噪——[TMI2022]ISCL: Interdependent Self-Cooperative Learning for Unpaired Image Denoising
Pytorch学习记录(七):处理数据和训练模型的技巧
PyTorch笔记——观察DataLoader&用torch构建LeNet处理CIFAR-10完整代码
Reading of denoising papers - [cvpr2022] blind2blind: self supervised image denoising with visible blind spots
深入理解去噪论文——FFDNet和CBDNet中noise level与噪声方差之间的关系探索
线性代数第一章-行列式
In depth understanding of the relationship between dncblevel and noise denoising in the paper
Pytorch学习记录(十):数据预处理+Batch Normalization批处理(BN)
Remedy after postfix becomes a spam transit station
Traitement des séquelles du flux de Tensor - exemple simple d'enregistrement de torche. Utils. Données. Dataset. Problème de dimension de l'image lors de la réécriture de l'ensemble de données
Pyqy5 learning (2): qmainwindow + QWidget + qlabel
创建企业邮箱账户命令
EditorConfig
深度学习基础——简单了解meta learning(来自李宏毅课程笔记)
Pytorch learning record (7): skills in processing data and training models