How to install JDBC driver in Eclipse web project without facing java.lang.ClassNotFoundexception

后端 未结 13 2832
梦毁少年i
梦毁少年i 2020-11-21 11:36

There is a VERY similar question to mine but in my case I don\'t have any duplicate jars in my build path, so the solution does not work for me. I\'ve searched google for a

13条回答
  •  鱼传尺愫
    2020-11-21 11:55

    The others are right about making the driver JAR available to your servlet container. My comment was meant to suggest that you verify from the command line whether the driver itself is intact.

    Rather than an empty main(), try something like this, adapted from the included documentation:

    public class LoadDriver {
        public static void main(String[] args) throws Exception {
            Class.forName("com.mysql.jdbc.Driver");
        }
    }
    

    On my platform, I'd do this:

    $ ls mysql-connector-java-5.1.12-bin.jar 
    mysql-connector-java-5.1.12-bin.jar
    $ javac LoadDriver.java 
    $ java -cp mysql-connector-java-5.1.12-bin.jar:. LoadDriver
    

    On your platform, you need to use ; as the path separator, as discussed here and here.

提交回复
热议问题