Guest User

Untitled

a guest
Mar 15th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.20 KB | None | 0 0
  1. package com.zj.testDB;
  2.  
  3. import java.sql.*;
  4.  
  5. public class TestDB {
  6.     public static void main(String[] args) {
  7. //       String driverName = "com.mysql.jdbc.Driver";
  8. //       String dbURL = "jdbc:mysql://localhost:3306/test";
  9. //       String userName = "root";
  10. //       String userPwd = "1111";
  11. //       Connection dbConn;
  12.  
  13.         String driverName = "com.microsoft.sqlserver.jdbc.SQLServerDriver"; // 加载JDBC驱动
  14.  
  15.         String dbURL = "jdbc:sqlserver://localhost:1433;integratedSecurity=true;DatabaseName=Botwave_test"; // 连
  16.  
  17.         String userName = "sa";
  18.         String userPwd = "1111";
  19.         Connection dbConn;
  20.  
  21.         try {
  22.             Class.forName(driverName).newInstance();
  23.             System.out.println("数据库驱动程序注册成功!");
  24.             dbConn = DriverManager.getConnection(dbURL, userName, userPwd);
  25.  
  26.             if (!dbConn.isClosed())
  27.                 System.out.println("数据库连接成功!");
  28.             dbConn.close();
  29.         } catch (ClassNotFoundException e) {
  30.             System.out.println("找不到驱动程序");
  31.             e.printStackTrace();
  32.         } catch (SQLException e) {
  33.             e.printStackTrace();
  34.         } catch (InstantiationException e) {
  35.             // TODO Auto-generated catch block
  36.             e.printStackTrace();
  37.         } catch (IllegalAccessException e) {
  38.             // TODO Auto-generated catch block
  39.             e.printStackTrace();
  40.         }
  41.     }
  42. }
Add Comment
Please, Sign In to add comment