java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver+数据库连接的工具类

【问题】

java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver

【解决】

1.添加jar包啊

sqlservler: sqljdbc4.jar

oracle: classes12.jar

mysql:  mysql。。。。。.jar.

===============================================数据库连接的工具类=====================================================

====oracle的写法:=======

     /*private static String   driver="oracle.jdbc.driver.OracleDriver";
 private static String url="jdbc:oracle:thin:@127.0.0.1:1521:hmaccp";
 private static String user="scott";
 private static String password="tiger";*/

=====sqlserver的写法:======

     private static String   driver="com.microsoft.sqlserver.jdbc.SQLServerDriver";
     private static String url="jdbc:sqlserver://127.0.0.1:1433;DatabaseName=message";
     private static String user="sa";
     private static String password="123456";
    public static Connection getConn(){
        Connection conn=null;
        try {
            Class.forName(driver);
            conn=DriverManager.getConnection(url,user,password);
            System.out.println("dd");
        } catch (Exception e) {                
            e.printStackTrace();
        }
        return conn;
    }
    public static void closeAll(Connection conn,Statement stmt,ResultSet rs){
        if(rs!=null){
            try {
                rs.close();
            } catch (Exception e) {                
                e.printStackTrace();
            }
        }
        if(stmt!=null){
            try {
                stmt.close();
            } catch (Exception e) {                
                e.printStackTrace();
            }
        }
        if(conn!=null){
            try {
                conn.close();
            } catch (Exception e) {                
                e.printStackTrace();
            }
        }
    }
    public static void main(String[] args) {
          getConn();
    }

================================================================================================================


版权声明:本文为u012726702原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。