I'm trying to get a MySQL database connection running in a Spring/Hibernate project in NetBeans. However, I always get a
java.sql.SQLException: No suitable driver found for "jdbc:mysql://127.0.0.1/test"
exception when deploying. None of the solutions I've read so far solve my problem.
applicationContext.xml:
<bean id="myDataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource"
p:driverClassName="com.mysql.jdbc.Driver"
p:url="${database.url}"
p:username="${database.username}"
p:password="${database.password}" />
where database.* is stored in a properties file. The jdbc connector .jar file is listed in libraries (ie. the classpath is set). When I expand it, com.mysql.jdbc.Driver is listed.
I have tried the natively installed connector and downloaded the newest version I could find (5.1.15). I can connect a jdbc connector that I have configured earlier using the same driver by clicking "connect" within the serviced tab in NetBeans. When using this sample code from outside the IDE, it also works:
import java.sql.*;
import java.util.Properties;
public class DBDemo
{
private static final String dbClassName = "com.mysql.jdbc.Driver";
private static final String CONNECTION = "jdbc:mysql://127.0.0.1/test";
public static void main(String[] args) throws ClassNotFoundException
{
System.out.println(dbClassName);
Class.forName(dbClassName);
Properties p = new Properties();
p.put("user","root");
p.put("password","root");
Connection c = DriverManager.getConnection(CONNECTION,p);
System.out.println("It works !");
c.close();
}
}
Any ideas on what I could be doing wrong?