当前位置:网站首页>The four connection methods of JDBC are directly coded
The four connection methods of JDBC are directly coded
2022-07-06 14:41:00 【MSjan】
Don't talk nonsense Code up Original handwriting
package JDBCbutton.FristStudy;
import com.mysql.jdbc.Driver;
import org.junit.Test;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;
public class Day02 {
public void connect1() throws SQLException {
//1. Registration drive
Driver driver = new Driver();
//2. Get links
//jdbc:mysql:// Is agreement
//localhost host , It can be IP Address
//3306 Express mysql Listening port
//hsp_db02 Connected database
String url = "jdbc:mysql://localhost:3306/zzs_db01";
// hold Account and password Put in Properties In the object
Properties properties =new Properties();
//user and password It's prescribed The actual situation later is
properties.setProperty("user","root");
properties.setProperty("password","123123");
// Get the connection
Connection connect =driver.connect(url,properties);
}
@Test
public void connect2() throws ClassNotFoundException, InstantiationException, IllegalAccessException, SQLException {
Class<?> aClass =Class.forName("com.mysql.jdbc.Driver");
//
Driver driver =(Driver) aClass.newInstance();
String url = "jdbc:mysql://localhost:3306/zzs_db01";
Properties properties =new Properties();
properties.setProperty("user","root");
properties.setProperty("password","123123");
Connection connect =driver.connect( url ,properties);
System.out.println(" Mode two = " +connect);
}
@Test
public void connect3() throws ClassNotFoundException, InstantiationException, IllegalAccessException, SQLException {
Class<?> aClass =Class.forName("com.mysql.jdbc.Driver");
Driver driver =(Driver) aClass.newInstance();
String url ="jdbc:mysql://localhost:3306/zzs_db01";
String user="root";
String password="123123";
DriverManager.registerDriver(driver);
Connection connection = DriverManager.getConnection(url, user, password);
System.out.println(" Method 3 = "+connection);
}
@Test
public void connect4() throws ClassNotFoundException, SQLException {
Class.forName("com.mysql.jdbc.Driver");// Use reflection to load
String url ="jdbc:mysql://localhost:3306/zzs_db01";
String user="root";
String password="123123";
Connection connection = DriverManager.getConnection(url, user, password);
System.out.println(" The fourth method ="+connection);
}
}Collect it If you forget, you can have a look !!
Don't forget to like it
边栏推荐
- Based on authorized access, cross host, and permission allocation under sqlserver
- Statistics 8th Edition Jia Junping Chapter 14 summary of index knowledge points and answers to exercises after class
- "If life is just like the first sight" -- risc-v
- 指针 --按字符串相反次序输出其中的所有字符
- JDBC 的四种连接方式 直接上代码
- 《统计学》第八版贾俊平第五章概率与概率分布
- Pointeurs: maximum, minimum et moyenne
- Statistics, 8th Edition, Jia Junping, Chapter 11 summary of knowledge points of univariate linear regression and answers to exercises after class
- Function: find the root of the equation by Newton iterative method
- 《统计学》第八版贾俊平第九章分类数据分析知识点总结及课后习题答案
猜你喜欢

Record an edu, SQL injection practice

关于交换a和b的值的四种方法

《统计学》第八版贾俊平第四章总结及课后习题答案

Statistics 8th Edition Jia Junping Chapter 14 summary of index knowledge points and answers to exercises after class

Hcip -- MPLS experiment

Statistics 8th Edition Jia Junping Chapter 10 summary of knowledge points of analysis of variance and answers to exercises after class

Data mining - a discussion on sample imbalance in classification problems
![Harmonyos application development -- address book management system telmanagesys based on listcontainer [phonebook][api v6]](/img/0b/ddbee0b8a34627e13bff5598bbaed8.jpg)
Harmonyos application development -- address book management system telmanagesys based on listcontainer [phonebook][api v6]

数字电路基础(四) 数据分配器、数据选择器和数值比较器

How to earn the first pot of gold in CSDN (we are all creators)
随机推荐
《统计学》第八版贾俊平第四章总结及课后习题答案
指針:最大值、最小值和平均值
Statistics 8th Edition Jia Junping Chapter 3 after class exercises and answer summary
《统计学》第八版贾俊平第十四章指数知识点总结及课后习题答案
Wu Enda's latest interview! Data centric reasons
Pointers: maximum, minimum, and average
MySQL中什么是索引?常用的索引有哪些种类?索引在什么情况下会失效?
How to earn the first pot of gold in CSDN (we are all creators)
【指针】求解最后留下的人
Pointer -- eliminate all numbers in the string
Mysql的事务是什么?什么是脏读,什么是幻读?不可重复读?
JDBC transactions, batch processing, and connection pooling (super detailed)
JDBC read this article is enough
Windows platform mongodb database installation
【指针】统计一字符串在另一个字符串中出现的次数
Circular queue (C language)
数字电路基础(五)算术运算电路
This article explains in detail how mockmvc is used in practical work
Library management system
[issue 18] share a Netease go experience