使用jdbc创建与SQL Server的连接时出现SQL异常

时间:2014-08-26 18:54:56

标签: jdbc sqlexception

使用jdbc创建与SQL Server的连接时出现以下错误。错误是:

java.sql.SQLException:没有为jdbc找到合适的驱动程序:sqlserver // D-PC // SQLEXPRESS; integratedSecurity = true 无法建立连接!

    import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import java.sql.Statement;

    /**  *  * @author Jatin  */ public class SQLConnect {
        public Connection sqlcon(Connection conn){
           try{
               Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
           }
           catch(ClassNotFoundException e){
               e.printStackTrace();
           }
           Statement stmt = null;
           try{
               conn = DriverManager.getConnection("jdbc:sqlserver//D-PC//SQLEXPRESS;integratedSecurity=true");
               stmt = conn.createStatement();
               stmt.executeUpdate("CREATE DATABASE Students");
               System.out.println("Database Created");
           }
           catch(SQLException e){
               e.printStackTrace();
           }
           if (conn != null) {      System.out.println("You made it, take control your database now!");     } else {        System.out.println("Failed to make connection!");   }
            return(conn);
        }
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) {
            Connection con =null;
           SQLConnect sqlcon = new SQLConnect();
           con = sqlcon.sqlcon(con);
        }

}

0 个答案:

没有答案