Showing posts with label Database Driver. Show all posts
Showing posts with label Database Driver. Show all posts

Wednesday, July 10, 2019

Solved - ClassNotFoundException: org.postgresql.util.PSQLException

When I was launching my program, I got the following error.

Exception in thread "main" java.lang.NoClassDefFoundError: org/postgresql/util/PSQLException
        at java.lang.Class.getDeclaredMethods0(Native Method)
        at java.lang.Class.privateGetDeclaredMethods(Class.java:2615)
        at java.lang.Class.getMethod0(Class.java:2856)
        at java.lang.Class.getMethod(Class.java:1668)
        at sun.launcher.LauncherHelper.getMainMethod(LauncherHelper.java:494)
        at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:486)
Caused by: java.lang.ClassNotFoundException: org.postgresql.util.PSQLException
        at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:358)

It was fixed by adding the database driver (postgresql-9.4.1209.jre7.jar) to the execution path.

-----------------------------------------------------------------------------------------------------------------
Watch the blessing and loving online channel: SupremeMasterTV live




If you have ever asked yourself these questions, this is the book for you. What is the meaning of life? Why do people suffer? What is in control of my life? Why is life the way it is? How can I stop suffering and be happy? How can I have a successful life? How can I have a life I like to have? How can I be the person I like to be? How can I be wiser and smarter? How can I have good and harmonious relations with others? Why do people meditate to achieve enlightenment? What is the true meaning of spiritual practice? Why all beings are one? Read the book for free here.

Tuesday, February 27, 2018

[Solved] java.sql.SQLException: ORA-28040: No matching authentication protocol

After you upgrade your Oracle database to 12c, you suddenly see this error when you try to connect remotely to your database through JDBC.

java.sql.SQLException: ORA-28040: No matching authentication protocol

at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:331)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:283)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:278)
at oracle.jdbc.driver.T4CTTIoauthenticate.receiveOsesskey(T4CTTIoauthenticate.java:294)
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:357)
at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:441)
at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:165)
at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:35)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:801)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)

To fix this problem:

Make sure the JDBC driver used by the client is ojdbc7.jar and all other drivers such as ojdbc14.jar are removed.

If the above does not fix this problem, on your Oracle server, open the file $ORACLE_HOME/network/admin/sqlnet.ora and add the line below to it.

SQLNET.ALLOWED_LOGON_VERSION=8

This SQLNET.ALLOWED_LOGON_VERSION parameter specifies the minimum authentication protocol allowed when connecting to Oracle Database instances. The value 8 permits most password versions, and allows any combination of the DBA_USERS.PASSWORD_VERSIONS values 10G, and 11G.

-----------------------------------------------------------------------------------------------------------------

                        
If you have ever asked yourself these questions, this is the book for you. What is the meaning of life? Why do people suffer? What is in control of my life? Why is life the way it is? How can I stop suffering and be happy? How can I have a successful life? How can I have a life I like to have? How can I be the person I like to be? How can I be wiser and smarter? How can I have good and harmonious relations with others? Why do people meditate to achieve enlightenment? What is the true meaning of spiritual practice? Why all beings are one? Read the book free here.

Thursday, April 10, 2014

Java DB, the Oracle open source database

Java DB is a full-featured, easy-to-use, open source database which is the Apache Derby open source database included in the java JDK starting version 5.

DBMS or Vendor: derby
Driver: org.apache.derby.jdbc.EmbeddedDriver
URL: when it is used before the database is created, the URL is jdbc:derby:<database name>;create=true, afterwards, the URL is simply  jdbc:derby:<database name>

You need to include the jars in the <java home>\db\lib directory in your project classpath for using the database.

Following is a sample code of using the Java DB.

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

public class JavaDBTest {
    private Connection conn = null;
    private boolean databaseCreated = false;
 
    private void createDatabase()
            throws ClassNotFoundException, SQLException {
        Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
        conn = DriverManager.getConnection(
                        "jdbc:derby:testDB;create=true");
        databaseCreated = true;
    }
 
    public Connection getConnection()
            throws ClassNotFoundException, SQLException{
        if (conn != null) return conn;
     
        if (databaseCreated) {
            Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
            conn = DriverManager.getConnection(
                        "jdbc:derby:testDB");
        } else {
            createDatabase();
        }
        return conn;
    }
    public static void main(String[] args){
        JavaDBTest test = new JavaDBTest();
        try {
            Connection connection = test.getConnection();
         
            DatabaseMetaData dmd = connection.getMetaData();
            System.out.println(dmd.getDriverName());
         
            Statement statement = connection.createStatement();
            statement.execute("create table fruit (name varchar(30), value varchar(20))");
            statement.executeUpdate("insert into fruit values ('Apple', '100')");

            ResultSet result = statement.executeQuery("select * from fruit");
            while(result.next()){
                System.out.println("name="+result.getString(1));
                System.out.println("value="+result.getString(2));
            }
            result.close();
            statement.close();
            connection.close();
        }catch(Exception e){
            e.printStackTrace();
        }
     
    }
}

References:
1.Java DB
2. Working with Java DB in NetBeans

-----------------------------------------------------------------------------------------------------------------

                        
If you have ever asked yourself these questions, this is the book for you. What is the meaning of life? Why do people suffer? What is in control of my life? Why is life the way it is? How can I stop suffering and be happy? How can I have a successful life? How can I have a life I like to have? How can I be the person I like to be? How can I be wiser and smarter? How can I have good and harmonious relations with others? Why do people meditate to achieve enlightenment? What is the true meaning of spiritual practice? Why all beings are one? Read the book free here.