0

My Code:

file ConnectionTest.java
package com.test.connection;

import java.io.InputStream;

import java.sql.*;
import java.util.Properties;

import org.junit.Test;



public class ConnectionTest {
@Test
public void getConnectTest5() throws Exception {
    //1、读取配置文件中的基本信息
    InputStream is = ConnectionTest.class.getClassLoader().getResourceAsStream("jdbc.properties");
    
    Properties pros = new Properties();
    pros.load(is);
    
    String user = pros.getProperty("user");
    String password = pros.getProperty("password");
    String url = pros.getProperty("url");
    String driverClass = pros.getProperty("driverClass");
    
    Class.forName("com.mysql.cj.jdbc.Driver");
    
    Connection conn = DriverManager.getConnection(url, user, password);
    System.out.println(conn);
} 

}

file jdbc.properties:

user=root password=Aa123456 url=jdbc:mysql://localhost:3306/test?serverTimezone=UTC&characterEncoding=utf-8&useSSL=false driverClass=com.mysql.cj.jdbc.Driver

Student
  • 1
  • 1

1 Answers1

-1

My Code Error: Loading class com.mysql.jdbc.Driver'. This is deprecated. The new driver class is com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.

Student
  • 1
  • 1
  • [Please edit your question](https://stackoverflow.com/posts/64001566/edit) to include the details and not post as answer. – FanoFN Sep 22 '20 at 00:41
  • Thank you, because the question is too long to display, A program error appears as an answer – Student Sep 23 '20 at 00:28