1import java.sql.*;
2class MySqlConn{
3 public static void main(String args[]){
4 try{
5 Class.forName("com.mysql.cj.jdbc.Driver");
6 Connection conn = DriverManager.getConnection("jdbc:mysql://
7 localhost:3306/databasename","username","password");
8 Statement stmt = conn.createStatement();
9 ResultSet rs = stmt.executeQuery("select * from emp");
10 con.close();
11 }catch(Exception ex){
12 System.out.println(ex);
13 }
14 }
15}
1<!-- MySQL dataSource config -->
2<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
3 <property name="driverClassName" value="com.mysql.cj.jdbc.Driver" /><!-- mysql 8 -->
4 <property name="url" value="jdbc:mysql://localhost:3306/mydb?useSSL=false&serverTimezone=UTC&characterEncoding=utf-8" />
5 <property name="username" value="matt" />
6 <property name="password" value="12345" />
7</bean>
8