开心的一天

package pkg22;

import java.sql.*;

import javax.sql.*;

public class Test{

  private static final String DRIVER="com.microsoft.sqlserver.jdbc.SQlServerDriver";

  private static final String URL="jdbc:sqlserver://localhost:1433;databasename=";

  private static final String DATABASE_NAME ="sqlti";

  private static final String USER_NAME = "sa";
  private static final String PASSWORD = "123";

  public static void main(String []args){
  try{
  Class.forName( DRIVER );
  Connection conn =   DriverManager.getConnection(URL+DATABASE_NAME,USER_NAME,PASSWORD);
    System.out.println("数据库连接成功"+conn);
  conn.close();
    }
  catch(ClassNotFoundException e){
    System.out.println("找不到驱动"+e.getMessage());
  }
  catch(SQLException e){
    System.out.println("驱动已经加载成功,发生其他异常:"+e.getMessage());
  }
    System.out.println("哈哈哈");
  }
  }

}

猜你喜欢

转载自www.cnblogs.com/l2760186162/p/10858601.html
今日推荐