当前位置:网站首页>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
边栏推荐
- Intranet information collection of Intranet penetration (5)
- 使用 flask_whooshalchemyplus jieba实现flask的全局搜索
- [pointer] solve the last person left
- [pointer] counts the number of times one string appears in another string
- 函数:计算字符串中大写字母的个数
- 线程的实现方式总结
- 1.支付系统
- 安全面试之XSS(跨站脚本攻击)
- 指针--剔除字符串中的所有数字
- Wu Enda's latest interview! Data centric reasons
猜你喜欢
数字电路基础(五)算术运算电路
Statistics 8th Edition Jia Junping Chapter IX summary of knowledge points of classified data analysis and answers to exercises after class
Statistics 8th Edition Jia Junping Chapter XIII Summary of knowledge points of time series analysis and prediction and answers to exercises after class
《统计学》第八版贾俊平第四章总结及课后习题答案
Fundamentals of digital circuit (V) arithmetic operation circuit
JDBC看这篇就够了
Solutions to common problems in database development such as MySQL
[paper reproduction] cyclegan (based on pytorch framework) {unfinished}
《統計學》第八版賈俊平第七章知識點總結及課後習題答案
Intranet information collection of Intranet penetration (3)
随机推荐
《统计学》第八版贾俊平第十四章指数知识点总结及课后习题答案
C language learning summary (I) (under update)
Intranet information collection of Intranet penetration (5)
This article explains in detail how mockmvc is used in practical work
《統計學》第八版賈俊平第七章知識點總結及課後習題答案
Constants, variables, and operators of SystemVerilog usage
AQS details
New version of postman flows [introductory teaching chapter 01 send request]
使用 flask_whooshalchemyplus jieba实现flask的全局搜索
函数:用牛顿迭代法求方程的根
《统计学》第八版贾俊平第十三章时间序列分析和预测知识点总结及课后习题答案
Functions: Finding Roots of equations
[pointer] find the length of the string
JDBC read this article is enough
循环队列(C语言)
Statistics 8th Edition Jia Junping Chapter 10 summary of knowledge points of analysis of variance and answers to exercises after class
内网渗透之内网信息收集(三)
【指针】求字符串的长度
"If life is just like the first sight" -- risc-v
Interview Essentials: what is the mysterious framework asking?