Home > other >  Error when trying to display data from oracle's table on console
Error when trying to display data from oracle's table on console

Time:12-29

I want to display database info on the console. Here is my main class code :

import java.sql.*;


public class main {

    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        // TODO Auto-generated method stub
        
        Class.forName("oracle.jdbc.driver.OracleDriver");
        Connection c=DriverManager.getConnection("jdbc:oracle:thin:hr/hr@localhost:1521/XE");
        Statement instruction = c.createStatement ();
        String query = "SELECT * FROM employees;";
        
        ResultSet r=instruction.executeQuery(query);
        
        while(r.next()) {
            System.out.println(r.getString("last_name"));
            
        }
        
        
    }

}

EDIT : I tried to add all the .jar file on my librarie and i have another error:

Error occurred during initialization of boot layer java.lang.module.ResolutionException: Modules xmlparserv2.sans.jaxp.services and xmlparserv2 export package oracle.xml.xqxp.datamodel to module osdt.core

I used the driver jdbc11 I'm on windows 8.1,Eclipse IDE, JDK 17 (x64)

CodePudding user response:

Java classpath loader can load classes from jar/zip files and from unpacked directories.

On the othere hand you have a .tar.gz file.

CodePudding user response:

I found the solution to this problem, just add all .jar files to the library remove the ; from

SELECT * FROM employees;
  • Related