#mysqluse
driver=com.mysql.jdbc.Driver
url=jdbc:mysql://127.0.0.1:3306/dotestuse
username=root
password=
紼嬪簭浠g爜
- import java.io.IOException;
- import java.io.InputStream;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- import java.util.Properties;
-
- public class GetConnectionT {
-
- public static void main(String[] args) {
-
- try {
-
- //璇誨彇閰嶇疆鏂囦歡鍙傛暟
- InputStream in = GetConnectionT.class.getClassLoader().getResourceAsStream("propert.properties");
- Properties pr = new Properties();
- pr.load(in);
- Class.forName(pr.getProperty("driver"));
- //閫氳繃椹卞姩綆$悊鍣ㄨ幏寰楁暟鎹簱榪炴帴
- Connection con = DriverManager.getConnection(pr.getProperty("url"), pr.getProperty("username"), pr.getProperty("password"));
- System.out.println(con);
- con.close();
-
- } catch (ClassNotFoundException e) {
-
- System.err.println("鍔犺澆椹卞姩澶辮觸"+e.getLocalizedMessage());
- } catch (IOException e) {
- System.err.println("鍔犺澆閰嶇疆鏂囦歡澶辮觸"+e.getLocalizedMessage());
- } catch (SQLException e) {
- System.err.println("寤虹珛鏁版嵁搴撹繛鎺ュけ璐?+e.getLocalizedMessage());
- }
- }
- }
榪欓噷鍙槸涓涓畝鍗曠殑鑾峰緱JDBC鐨勪緥瀛愶紝鍦ㄥ疄闄呭伐浣滀腑鎴戜滑鏈濂界敤鍗曚緥妯″紡鏉ヨ幏寰楁暟鎹簱榪炴帴