当前位置:网站首页>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
边栏推荐
- Fire! One day transferred to go engineer, not fire handstand sing Conquest (in serial)
- MySQL中什么是索引?常用的索引有哪些种类?索引在什么情况下会失效?
- Numpy快速上手指南
- Statistics, 8th Edition, Jia Junping, Chapter VIII, summary of knowledge points of hypothesis test and answers to exercises after class
- Statistics 8th Edition Jia Junping Chapter 10 summary of knowledge points of analysis of variance and answers to exercises after class
- [paper reproduction] cyclegan (based on pytorch framework) {unfinished}
- 我的第一篇博客
- Statistics 8th Edition Jia Junping Chapter 5 probability and probability distribution
- Uibutton status exploration and customization
- Lintcode logo queries the two nearest saplings
猜你喜欢
《统计学》第八版贾俊平第三章课后习题及答案总结
Lintcode logo queries the two nearest saplings
链队实现(C语言)
《统计学》第八版贾俊平第十二章多元线性回归知识点总结及课后习题答案
《统计学》第八版贾俊平第十四章指数知识点总结及课后习题答案
关于交换a和b的值的四种方法
JDBC事务、批处理以及连接池(超详细)
Realize applet payment function with applet cloud development (including source code)
《统计学》第八版贾俊平第五章概率与概率分布
Intel oneapi - opening a new era of heterogeneity
随机推荐
Internet Management (Information Collection)
《统计学》第八版贾俊平第十章方差分析知识点总结及课后习题答案
Interview Essentials: what is the mysterious framework asking?
使用 flask_whooshalchemyplus jieba实现flask的全局搜索
Mathematical modeling idea of 2022 central China Cup
指针--剔除字符串中的所有数字
Statistics, 8th Edition, Jia Junping, Chapter 6 Summary of knowledge points of statistics and sampling distribution and answers to exercises after class
SystemVerilog discusses loop loop structure and built-in loop variable I
Function: find the root of the equation by Newton iterative method
函数:字符串反序存放
“人生若只如初见”——RISC-V
JDBC 的四种连接方式 直接上代码
[pointer] find the length of the string
指針:最大值、最小值和平均值
Network technology related topics
Pointeurs: maximum, minimum et moyenne
Hcip -- MPLS experiment
Lintcode logo queries the two nearest saplings
[pointer] use the insertion sorting method to arrange n numbers from small to large
Keil5-MDK的格式化代码工具及添加快捷方式