简体   繁体   中英

netbeans with glassfish have no suitable driver found for mysql:jdbc

I am a noob in java ee

But to learn it I should connect to mysql!

I have googled about a day:

Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection connection = DriverManager.getConnection("mysql:jdbc://127.0.0.1:3036/shedule", "root", "12345");

said:

java.sql.SQLException: No suitable driver found for mysql:jdbc://127.0.0.1:3036/shedule

0) mysql -h 127.0.0.1 -P 3306 -u root -p works

2) netstat said that mysqld listened to 0.0.0.0:3306

3) lastest netbeans 6.9.1 + glassfish 3.0.1

4) I have ONLY mysql-connector-java-5.1.6-bin.jar no other jars! searched at all hard drives before and after deploy!

it seat at: D:\\Program Files\\NetBeans 6.9\\ide\\modules\\ext and D:\\NetBeansProjects\\MyProject\\build\\web\\WEB-INF\\lib

5) I have selected "add Library" and mysql-connector-java-5.1.6-bin.jar

6) people said that netbeans deploy this jar to D:\\Program Files\\glassfish-3.0.1\\glassfish\\domains\\domain1\\lib But after deploy there are no mysql-connector-java-5.1.6-bin.jar

7) I have unpacked source of this connector (5.1.14) to my src/java folder

added libraries ant-contrib.jar c3p0-0.9.1-pre6.jar and jboss-common-jdbc-wrapper.jar

My project builds and deploys normaly but work with this exception!

Finaly: 替代文字

That error means your URL is incorrect. That's what that exception usually means.

"mysql:jdbc://127.0.0.1:3036/shedule"  

should be this:

"jdbc:mysql://127.0.0.1:3306/shedule"

The "jdbc" and "mysql" are backwards. And, as noted earlier, the default port is incorrect.

You'll have to reverse all that crazy stuff you tried to fix this. You should have the MySQL connector JAR in one place, either a /lib directory for your app server if it's shared or in WEB-INF/lib of your application. Nowhere else.

I see one inconsistency:

Connection connection = DriverManager.getConnection("mysql:jdbc://127.0.0.1:3036/shedule", "root", "12345");

you're specifying 3036 as port.

Later on you say:

netstat said that mysqld listened to 0.0.0.0:3306

From my experience, 3036 != 3306

all you have to do in netbeans is 1. start a new Java web application project 2. download the latest JDBC driver from here; rite now its running at 5.1.14 3. extract that file, and physically copy and paste the .jar folder into the "Libraries" folder of your netbeans web application project. 4. thats it.

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