当前位置:网站首页>Detailed steps of JDBC connection to database
Detailed steps of JDBC connection to database
2022-07-29 05:47:00 【Just learning records】
One 、 Create a project first
Two 、 Open the database and start the connection
( I was in IDEA Written in , Guide package in advance )
3、 ... and 、 No, the guide bag is Maven Midcourse , stay pom.xml Medium dependencise discharge , The version number depends on whether you want a higher version or a lower version . Put it in and then refresh and reload it to maven Rely on yourself .
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.47</version>
</dependency>
Detailed code :
package com.example.dem02; // Project package name
import java.sql.*;
public class jdbcText01 {
public static void main(String[] args){
Connection conn = null;
Statement stmt = null;
try{
//1、 Registration drive
DriverManager.registerDriver(new com.mysql.jdbc.Driver());
//Class.forName("com.mysql.jdbc.Driver");
//2、 Get the connection
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/student","root","root");
//3、 Get database operation object
stmt = conn.createStatement();
//4、 perform sql sentence
String sql = "INSERT INTO class(Sid,Sname,Sage,Sgrade)VALUES ('003',' indigo plant ','19','89')";
int count = stmt.executeUpdate(sql);
System.out.println(count == 1 ? " The update is successful ": " Update failed ");
//5、 Process the project result set
}catch (SQLException e){
e.printStackTrace();
}finally {
//6、 Release resources
if (stmt != null){
try{
stmt.close();
}catch(SQLException e ){
e.printStackTrace();
}
}
if(conn != null){
try{
conn.close();
}catch(SQLException e){
e.printStackTrace();
}
}
}
}
}
边栏推荐
- 熊市慢慢,Bit.Store提供稳定Staking产品助你穿越牛熊
- Installation steps and environment configuration of vs Code
- Okaleido tiger logged into binance NFT on July 27, and has achieved good results in the first round
- Seay源代码审计系统
- DAY15(DAY16拓展):文件包含漏洞
- Use QSS to style the form
- 超简单集成HMS ML Kit 人脸检测实现可爱贴纸
- Solve the problem that the prompt information of form verification does not disappear and the assignment does not take effect
- Fantom (FTM) 在 FOMC会议之前飙升 45%
- [C language series] - constants and variables that confuse students
猜你喜欢
ThinkPHP6 输出二维码图片格式 解决与 Debug 的冲突
DAY5:PHP 简单语法与使用
Sqlmap是什么以及使用方法
Crypto巨头们ALL IN元宇宙,PlatoFarm或能突围
运动健康深入人心,MOVE PROTOCOL引领品质生活
Starfish OS: create a new paradigm of the meta universe with reality as the link
Go|Gin 快速使用Swagger
WIN10 编译ffmpeg(包含ffplay)
Seay源代码审计系统
MySQL decompressed version windows installation
随机推荐
[electronic circuit] how to select ADC chip
Liang Yuqi, founder of aitalk: the link between image and virtual reality
Wechat applet - screen height
机器学习让文字识别更简单:Kotlin+MVVM+华为ML Kit
Under the bear market of encrypted assets, platofarm's strategy can still obtain stable income
JS simple code determines whether the device that opens the page is the PC end of the computer, the H5 end of the mobile phone, or the wechat end
Introduction to C language array to proficiency (array elaboration)
如何零代码制作深度学习的趣味app(适合新手)
Record the SQL injection vulnerability of XX company
How can Plato obtain premium income through elephant swap in a bear market?
Sliding switch of tab of uniapp component
From starfish OS' continued deflationary consumption of SFO, the value of SFO in the long run
麦当娜“Hellbent”购买130万美元的nft无聊猿,现在被认为太贵了
QT setting background image method
Dao race track is booming. What are the advantages of m-dao?
uniapp组件之选择选项(如套餐选择)
闪贷Dapp的调研及实现
Starfish OS: create a new paradigm of the meta universe with reality as the link
改哭了,终于解决了Cannot read properties of undefined (reading ‘parseComponent‘)
Detailed explanation of typical application code of C language array - master enters by mistake (step-by-step code explanation)