0

Since I don't have netbeans right now, I am trying to connect to MySQL database from my Java code through command prompt. But it it is not taking the mysql-coonectivity.jar file.

Does anyone know any way to run my program??? Please help.

3
  • What do you mean by it is not taking? Also, please consider adding the code you are trying to run. You may also want to check this answer. Commented Sep 2, 2014 at 3:37
  • Please help us help you. What program? Does it work in netbeabs? How is it not taking the file? Have you checked the spelling? Commented Sep 2, 2014 at 3:38
  • 1
    As you are new user here, let me tell you, if you find the solution of your problem here in the answers, then you should accept the answer, to let others know what worked for you. To do so, you should click on the right sign tick on the left side of answer below the up down arrows. Commented Sep 2, 2014 at 5:33

3 Answers 3

4

Try executing the program as it is windows OS

java -cp .;path\of\your\mysql-connector-java-5.1.6.jar className

In case you don't have the mysql-connector-java-[version].jar get it from here

Sign up to request clarification or add additional context in comments.

Comments

3

You need to add your MySQL connector jar file while compiling and running your program, you can do it the following way,

To compile :

javac -g -cp mysql-coonectivity.jar; YourFileName.java

To Run

java -cp mysql-coonectivity.jar; YourMainClass

NOTE: The above written syntax assumes that your jar file is present at same location as of your program.

2 Comments

my program has compiled successfully but when i try to execute it, i get an error when i try to run, i get an exception java.lang.NoClassDefFoundError. Please help.
@user3359330 NoClassDefFoundError for which class?
0

To execute program in Linux (Ubuntu) OS follow the below command format:

java -cp .:/usr/share/java/mysql-connector-java-8.0.25.jar MainProgram

Note:

  1. Assuming you are in the directory where MainProgram.class is exist
  2. After .(dot -- this is for current directory) there is :(colon) as a separator in Linux

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.