简体   繁体   中英

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

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)

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

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

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

SELECT * FROM employees;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM