当前位置:网站首页>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
边栏推荐
- Database monitoring SQL execution
- flask实现强制登陆
- 函数:用牛顿迭代法求方程的根
- Using flask_ Whooshalchemyplus Jieba realizes global search of flask
- JDBC事务、批处理以及连接池(超详细)
- Feature extraction and detection 14 plane object recognition
- Statistics 8th Edition Jia Junping Chapter XIII Summary of knowledge points of time series analysis and prediction and answers to exercises after class
- Internet Management (Information Collection)
- 《统计学》第八版贾俊平第十四章指数知识点总结及课后习题答案
- [pointer] solve the last person left
猜你喜欢
四元数---基本概念(转载)
《统计学》第八版贾俊平第十三章时间序列分析和预测知识点总结及课后习题答案
Record an API interface SQL injection practice
Fundamentals of digital circuit (V) arithmetic operation circuit
Circular queue (C language)
New version of postman flows [introductory teaching chapter 01 send request]
Library management system
《统计学》第八版贾俊平第十四章指数知识点总结及课后习题答案
5分钟掌握机器学习鸢尾花逻辑回归分类
Intel oneapi - opening a new era of heterogeneity
随机推荐
使用 flask_whooshalchemyplus jieba实现flask的全局搜索
[pointer] find the largest string
浙大版《C语言程序设计实验与习题指导(第3版)》题目集
Interview Essentials: what is the mysterious framework asking?
MySQL中什么是索引?常用的索引有哪些种类?索引在什么情况下会失效?
Function: find the maximum common divisor and the minimum common multiple of two positive numbers
Database monitoring SQL execution
“Hello IC World”
Fundamentals of digital circuit (IV) data distributor, data selector and numerical comparator
《统计学》第八版贾俊平第四章总结及课后习题答案
函数:求两个正数的最大公约数和最小公倍
2022华中杯数学建模思路
后台登录系统,JDBC连接数据库,做小案例练习
Record an API interface SQL injection practice
Statistics, 8th Edition, Jia Junping, Chapter 11 summary of knowledge points of univariate linear regression and answers to exercises after class
C language learning summary (I) (under update)
《统计学》第八版贾俊平第七章知识点总结及课后习题答案
[pointer] counts the number of times one string appears in another string
Using flask_ Whooshalchemyplus Jieba realizes global search of flask
servlet中 servlet context与 session与 request三个对象的常用方法和存放数据的作用域。