Skip to content Skip to sidebar Skip to footer

Class Notfound Exception In Sqlserver Connection In Eclipse

My servlet function looks like these: CODE: protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

Solution 1:

try {
        Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
        conn = DriverManager.getConnection("jdbc:sqlserver://192.168.0.123:1433;databaseName=test", "sample", "sample");
    } catch (ClassNotFoundException e) {
        System.out.println( "Couldn’t load drivers!" );
    } catch (SQLException e) {
        System.out.println("Couldnot get connection");
    }

or

try {
        Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
        conn = DriverManager.getConnection("jdbc:sqlserver://192.168.0.123:1433;databaseName=test", "sample", "sample");
    } catch (Exception e) {
        if (e instanceof ClassNotFoundException) {
             System.out.println( "Couldn’t load drivers!" );
        } else {
            if (e instanceof SQLException) {
                System.out.println("Couldnot get connection");
            }
        }
    }

Post a Comment for "Class Notfound Exception In Sqlserver Connection In Eclipse"