I can't load the JDBC driver for MySQL

前端 未结 3 1243
萌比男神i
萌比男神i 2021-01-13 02:47

I\'ve been trying to load the JDBC MySQL connector with the following code:

import java.sql.*;

public class dbTest{
   public static void main(String[] args         


        
3条回答
  •  再見小時候
    2021-01-13 03:29

    There are two classpaths in java. Build path and run path. Build path is used when compiling .java files into .class files. In a language like C you have a linker stage that fills in all the missing symbols when you run the linker on a bunch of object files. Thats why for .exe(windows) or other native binaries(linux) there is no run path. Java is slightly different because the compiled .class definitions get loaded by the jvm as they are needed.

    What the net out of this is that you have to supply a runtime classpath to the jvm. At the command line you use java.exe which searches a few places by default including $CLASSPATH, the current directory/lib, and whatever you supply to the -cp option.

    IDEs are different from the command line because they are attempting to shield you from some of the nastiness of running java.exe and supplying the locations where all the .class files are(which would be onerous on a large project).

    Most IDE's have some sort of "Run Configuration" tab that allows you to specify certain libraries or locations with classes that will be used when you run your application. Below is how to set the run path in eclipse,netbeans, and intellij.

    http://javahowto.blogspot.com/2006/06/set-classpath-in-eclipse-and-netbeans.html

    http://www.jetbrains.com/idea/webhelp/run-debug-configuration-application.html

提交回复
热议问题