当前位置:网站首页>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();
}
}
}
}
}
边栏推荐
- Win10 compiles ffmpeg (including ffplay)
- 量化开发必掌握的30个知识点【什么是Level-2数据】
- The Platonic metauniverse advocated by musk has long been verified by platofarm
- 【电子电路】ADC芯片如何选型
- win10+opencv3.2+vs2015配置
- HCIA-R&S自用笔记(24)ACL
- Countdown of the uniapp component (such as the countdown to reading the agreement and the countdown to completing learning)
- HCIA-R&S自用笔记(25)NAT技术背景、NAT类型及配置
- Okaleido tiger logged into binance NFT on July 27, and has achieved good results in the first round
- [JS question solution] questions 1-10 in JS of niuke.com
猜你喜欢
![[typescript] learn typescript object types in depth](/img/87/a9fd2f177331863e06fcf14559eeed.png)
[typescript] learn typescript object types in depth

365 day challenge leetcode1000 question - day 036 binary tree pruning + subarray and sorted interval sum + delete the shortest subarray to order the remaining arrays

Seay源代码审计系统

How can Plato obtain premium income through elephant swap in a bear market?

深度学习的趣味app简单优化(适合新手)

Introduction to C language array to proficiency (array elaboration)

华为2020校招笔试编程题 看这篇就够了(上)

改哭了,终于解决了Cannot read properties of undefined (reading ‘parseComponent‘)

uniapp组件之tab选项卡滑动切换

The LAAS protocol of defi 2.0 is the key to revitalizing the development of defi track
随机推荐
Starfish OS:以现实为纽带,打造元宇宙新范式
[JS question solution] questions 1-10 in JS of niuke.com
ThinkPHP6 输出二维码图片格式 解决与 Debug 的冲突
365 day challenge leetcode 1000 questions - day 035 one question per day + two point search 13
Countdown of the uniapp component (such as the countdown to reading the agreement and the countdown to completing learning)
uniapp页面标题显示效果
Seay source code audit system
Mobile terminal -flex item attribute
Use QSS to style the form
机器学习让文字识别更简单:Kotlin+MVVM+华为ML Kit
农村品牌建设给年轻人的一些机会
Extreme deflation and perpetual motion machine model will promote the outbreak of platofarm
Crypto巨头们ALL IN元宇宙,PlatoFarm或能突围
华为2020校招笔试编程题 看这篇就够了(下)
dcat 批量操作弹窗及参数传递
一文读懂Move2Earn项目——MOVE
闪贷Dapp的调研及实现
Masscan使用教程.
Basic concepts of MySQL + database system structure + extended application + basic command learning
Qt设置背景图片方法