Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Driver not found in Netbeans IDE

I have read all possible answer here and here and here. I believe I have a problem somewhere else and it may useful to others also.

I have a Java Servlet and it was executing well in eclipse IDE but later I shifted the project to Netbeans. I imported MySQL JDBC driver in Libraries and using the code below for connection

connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/bolsms", "root", "@#$5869@#$");

but I am getting this error No suitable driver found for jdbc:mysql://localhost:3306/bolsms

I looking for answer for two days and community will appreciate that I am not repeating the question.

Edit 1:

MySQL JDBC driver in Libraries Folder

like image 444
Gaurav Agarwal Avatar asked Apr 10 '12 12:04

Gaurav Agarwal


People also ask

How do I download JDBC driver?

Use a web browser to visit the MySQL download site and locate the source and binary download link for the archive format that you want to use (typically zip for Microsoft Windows systems or a gzipped tarball for Linux systems). Click that link to initiate the download process. Registration may be required.


2 Answers

When you use it in Tomcat you have to explicitly load jdbc driver. I experienced the same error in a servlet in Tomcat. And adding Class.forName("com.mysql.jdbc.Driver"); solve it.

The other thing I think, is to put the jar file in your WEB-INF/lib, then in your project properties, in Libraries, add the JAR you store in WEB-INF/lib.

To create the lib directory, right click on WEB-INF and choose New -> Folder... If you don't see Folder choose Other then in the new windows choose Other again and Folder.

The Tomcat / JDBC issue is referenced here for more information.

like image 155
alain.janinm Avatar answered Oct 12 '22 19:10

alain.janinm


Include the following piece of code in your code:

Class.forName("com.mysql.jdbc.Driver");//load driver
connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/bolsms", "root", "@#$5869@#$");//connect to the database
like image 23
mykey Avatar answered Oct 12 '22 19:10

mykey