没有为jdbc找到合适的驱动程序:mysql:// localhost:3306 / database

时间:2014-07-30 02:13:55

标签: java netbeans jdbc

我正在使用NetBeans来学习如何在Java中使用sql。但是,即使我做的一切正常,我也会收到错误。这是我的连接声明:

connection = DriverManager.getConnection("jbdc:mysql://localhost:3306/database", 
    "root", "MsqJ449?");

另外,我将mysql-connector-java-5.1.31-bin.jar添加到NetBeans中的Properties下的Compile Time和Run Time库中。该数据库存在于MySQL中。问题还有什么呢?

2 个答案:

答案 0 :(得分:-2)

您需要通过调用:

来加载驱动程序
Class.forName("com.mysql.jdbc.Driver");

在你使用它之前的某个时刻。

答案 1 :(得分:-2)

需要通过Class.forName(drivername)方法将jdbc驱动程序加载到JVM,尝试在连接之前调用此方法。

相关问题