0

I was trying to connect java with MySQL. I downloaded the connector and added it to classpath of the app on Eclipse IDE and also moved to the "Referenced Libraries" on VSCode. Different projects each ones.

On Eclipse it worked fine, but VSCode display this error:

PS C:\Users\User\Desktop\Programação\Java\J19>  c:; cd 'c:\Users\User\Desktop\Programação\Java\J19'; & 'C:\Program Files\Java\jdk-19\bin\java.exe' '-XX:+ShowCodeDetailsInExceptionMessages' '@C:\Users\User\AppData\Local\Temp\cp_fw615ezm0w8yc6egf85gzwbb.argfile' 'App' 
**Error: Could not find or load main class App
Caused by: java.lang.ClassNotFoundException: App**

I realized this error occurs with any jar files I add, not only with the MySQL connector.
I already tried to reinstall VSCode, reinstall java, and change from Java 17 to 19 and nothing fix it.

Some more data:

VSCode Version: 1.72.0 (User Setup)
MySql Version: 8.0.30 Build 2054668 CE
Connector: mysql-connector-java-8.0.30.jar
Eclipse Version: 2022-09 (4.25.0) Build id 20220908-1902

Edit 1:

This is the code:

package banco;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
        
public class App {
    public static void main(String[] args) {
        final String db_url = "jdbc:mysql://localhost:3306/reuniao";
        final String db_query = "SELECT * FROM pessoa";
        final String db_user = "root";
        final String db_password = "";
        // Pessoa[]p;
        // int reultSetRows = 0;
        System.out.println("Iniciando conexão com o DB.");
        try (Connection c = DriverManager.getConnection(db_url, db_user, db_password);
                Statement statement = c.createStatement();
                ResultSet resultSet = statement.executeQuery(db_query)) {
            System.out.println("Conectado ao MySQL");
        
        } catch (SQLException sqlException) {
            sqlException.printStackTrace();
        }
    }
}

The project was created with Command Pallete (Ctrl+Shift+P) - Create Java Project - No build Tools - Selected my Code Folder and named my project - Created package and start coding.

Danon
  • 2,771
  • 27
  • 37
Ternes
  • 11
  • 2
  • Please see [ask] and check your grammar. There are tools online. – HoRn Oct 10 '22 at 05:54
  • Under the exact same environment (VScode version, MySQL version, jar version.), my machine has no problems. Can you describe in detail how you created the project and how to run your code?? If possible, show your error interface and post the relevant code. – JialeDu Oct 11 '22 at 06:02
  • try **Ctrl + Shift + P** --> `Java: Clean Java Language Server Workspace`. – JialeDu Oct 11 '22 at 06:05
  • @HoRn Cant help with my problem? – Ternes Oct 11 '22 at 12:57
  • @JialeDu Already tried, Still with the problem. Updating the post with the code and project details. – Ternes Oct 11 '22 at 13:04
  • Follow your steps to reproduce [without problems](https://imgur.com/k3AtwzU). Please show your project structure. In addition, the first line of `Package banco` in your code should be `package banco`, lowercase `p`. Here's an [answer](https://stackoverflow.com/a/73644505/19133920) I wrote before that might help. – JialeDu Oct 12 '22 at 01:58
  • Sorry to bother, any update on the question? – JialeDu Oct 21 '22 at 08:39

0 Answers0