本文共 841 字,大约阅读时间需要 2 分钟。
package com.company;import java.sql.*;public class Main { public static void main(String [] args) { String driverName="com.mysql.cj.jdbc.Driver"; String dbURL="jdbc:mysql://localhost:3306/jxgl?serverTimezone=UTC&useSSL=true"; String userName="root"; String userPwd="123456"; try { Class.forName(driverName); System.out.println("加载驱动成功!"); }catch(Exception e){ e.printStackTrace(); System.out.println("加载驱动失败!"); } try{ Connection dbConn=DriverManager.getConnection(dbURL,userName,userPwd); System.out.println("连接数据库成功!"); }catch(Exception e) { e.printStackTrace(); System.out.print("SQL Server连接失败!"); } }}
转载地址:http://ohtg.baihongyu.com/