Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.zj.testDB;
- import java.sql.*;
- public class TestDB {
- public static void main(String[] args) {
- // String driverName = "com.mysql.jdbc.Driver";
- // String dbURL = "jdbc:mysql://localhost:3306/test";
- // String userName = "root";
- // String userPwd = "1111";
- // Connection dbConn;
- String driverName = "com.microsoft.sqlserver.jdbc.SQLServerDriver"; // 加载JDBC驱动
- String dbURL = "jdbc:sqlserver://localhost:1433;integratedSecurity=true;DatabaseName=Botwave_test"; // 连
- String userName = "sa";
- String userPwd = "1111";
- Connection dbConn;
- try {
- Class.forName(driverName).newInstance();
- System.out.println("数据库驱动程序注册成功!");
- dbConn = DriverManager.getConnection(dbURL, userName, userPwd);
- if (!dbConn.isClosed())
- System.out.println("数据库连接成功!");
- dbConn.close();
- } catch (ClassNotFoundException e) {
- System.out.println("找不到驱动程序");
- e.printStackTrace();
- } catch (SQLException e) {
- e.printStackTrace();
- } catch (InstantiationException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IllegalAccessException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
Add Comment
Please, Sign In to add comment