Search code examples
javadatabasederby

org.apache.derby.jdbc.ClientDriver ; unable to connect


Unable to connect. Cannot establish a connection to jdbc:derby://localhost:1527/sample using org.apache.derby.jdbc.ClientDriver (DERBY SQL error: ERRORCODE: 40000, SQLSTATE: XJ040, SQLERRMC: Failed to start database 'sample' with class loader sun.misc.Launcher$AppClassLoader@1d44bcfa, see the next exception for details.::SQLSTATE: XSLAN).


Solution

  • When you do a connection you should put it into a try/catch. For example ( I use Java 8 and oracle SQLDeveloper ) :

     String dbURL="jdbc:oracle:thin:@localhost:1521:xe";
        String username = "system";
        String password = "root";
    
    
        try{
    
        Connection connection = DriverManager.getConnection(dbURL,username,password);
            System.out.println("Connected to Oracle database server");
    
            
            String sql = "INSERT INTO USERS (name,email,password)" + "VALUES('eu', 'eu@yahoo.com', 'eu')";
    
            Statement statement = connection.createStatement();
            int rows = statement.executeUpdate(sql);
    
            if(rows >0){
                System.out.println("A row has been inserted");
            }
    
    
    
            connection.close();
        }catch (SQLException e){
            System.out.println("ERROR");
        }
    

    And always check for right password and username. Hope this helps. :D