D
D
daMage2014-08-29 07:25:13
Java
daMage, 2014-08-29 07:25:13

How to connect JDBC?

Help to connect the driver to work with mysql. Base class code

class App {
 	public static void main(String[] args) {
    try {
      Class.forName("com.mysql.jdbc.Driver");
      System.out.println("Driver loading success!");
    }
    catch(ClassNotFoundException e) {
      e.printStackTrace();
    }
  }
}

writing
javac App.java
java -cp mysql-connector-java-5.1.32-bin.jar App

and I get "Error: Could not find or load main class App"
When I remove "-cp mysql-connector-java-5.1.32-bin.jar", an exception is thrown.
If you write -jar instead of -cp, then it says: "no main manifest attribute, in mysql-connector-java-5.1.32-bin.jar". Googled and found a solution - add Main-Class. Added the line Main-Class: App, the error remained.
The base class, like the connector, is in the same directory. I spent the whole day in vain, help, please.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladislav Gasanov, 2014-08-29
@kosmoflyko

The JVM cannot find the App.class file because in CLASSPATH you passed only Jar Mysql. Run like this:
java -cp .;mysql-connector-java-5.1.25-bin.jar App The
dot in the expression points to the current directory.

V
Vitaly, 2014-09-05
@silverhawk90

It will be easier to connect the mysql-connector-java-5.1.32-bin.jar driver in the project settings as a library and the assembler will pull it into the project

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question