简体   繁体   中英

JDBC mysql Wamp

I've downloaded the MySQL JDBC driver. In my Eclipsoe project I modified the build path so that the mysql-connector-java.bin.jar is there and I can call functions from that jar.

When run the application from Eclipse, everything is fine and a proper connection to the MySql db is made.

However, when I upload and run the application on my WampServer,

        try {

            Class.forName("com.mysql.jdbc.Driver");

        } catch (ClassNotFoundException e) {

            System.out.println("Where is your MySQL JDBC Driver?");
            e.printStackTrace();
            addItem("Class not found");
            return;

        }

it seems to not go into the ClassNotFoundExeption block of the try-catch.

Any insight as to what I'm doing wrong?

You have jar in build path, but it seems you are missing it in runtime. If it is web application, add mysql jar to lib folder of web application.

If you are using Java Project rather web application you should build path for the mysql jar.

Steps for Java project 1)Right click on your java project and choose preferences. 2)In window dialog click on Java build path and then click on Libraries tab. 3)Now click on add external jars for addding mysql jar.

For web application you need to put the jar to lib directory.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM