Reputation: 2984
I have a class named "Sta"
.
Every time I try to connect to the mysql Database I run into the exception:
2012/07/23 03:34:50SQLException: No suitable driver found for mysql:jdbc://127.0.0.1:3306/sta?user=root.. This exception like said occurs at: this.db_con=DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/sta?user=root");
What I've done so far is:
put the driver jar manually into WEB-INF/lib (creaded the lib), and
also put it into the library directory of the tomcat.
All with the same result (I'm using: mysql-connector-java-5.1.20-bin.jar )
The project itself compiles and deploys normally except for the above exception. Furthermore if I use the same connectionstring for a "normal" java - RMI application it works fine and without any hitches.
public class Sta_client extends HttpServlet
{
private Connection db_con=null;
public Sta_client() throws ServletException
{
super();
if (this.db_con==null)
{
try
{
Class.forName("com.mysql.jdbc.Driver");
}
catch(java.lang.ClassNotFoundException e)
{
System.err.print("ClassNotFoundException: ");
System.err.println(e.getMessage());
}
try
{
this.db_con=DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/sta?user=root");
}
catch(SQLException ex)
{
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
Date date = new Date();
System.err.println(dateFormat.format(date)+"SQLException: " + ex.getMessage());
}
}
}
Upvotes: 0
Views: 3877
Reputation: 6738
Netbeans 7.0.1 has mysql connector.Remove your mysql-connector-java-5.1.20-bin.jar and add jar that support in NetBeans IDE.
Upvotes: 0