file not found error occurs when trying to get connection string java

415 Views Asked by At

I'm using Eclipse IDE. Did everything by the book. Added the connector to the classpath. The database works fine. Show table command shows the table in cmd. but still gives the below error when runs the code:

Exception in thread "main" java.lang.Error: java.io.FileNotFoundException: C:\Users\Beta\AppData\Local\Temp\eoiAEF1.tmp\plugins\org.eclipse.justj.openjdk.hotspot.jre.minimal.stripped.win32.x86_64_14.0.2.v20200815-0932\jre\lib\tzdb.dat (The system cannot find the file specified)

Below is the code:

package test;

import java.sql.*;
public class testDB {

    public static void main(String[] args) throws ClassNotFoundException {
        // TODO Auto-generated method stub
        System.out.println("Hello");
        try{  
            Class.forName("com.mysql.cj.jdbc.Driver");  
            Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/sonoo","root","root");  
            //here sonoo is database name, root is username and password  
            Statement stmt=con.createStatement();  
            ResultSet rs=stmt.executeQuery("select * from emp");  
            while(rs.next())  
            System.out.println(rs.getInt(1)+"  "+rs.getString(2)+"  "+rs.getString(3));  
            con.close();  
            }
        catch(SQLException e){
            e.printStackTrace();
            } 
        catch(Exception e) {
            System.out.println(e);
        }

    }

}

Any help would be greatly appreciated. Thank you!

0

There are 0 best solutions below