我在我的電腦上安裝了Xampp和mysql數據庫。現在我想爲我的java JDBC程序使用這個mysql數據庫。爲此我寫了下面的程序。從Xampp爲java jdbc程序使用mysql
package mysqltype4driverdemo;
import java.sql.*;
import java.util.*;
public class MysqlType4DriverDemo {
public static void main(String[] args)throws SQLException {
String url="jdbc:mysql://localhost:3306/mysql";
Properties prop=new Properties();
prop.setProperty("user","root");
prop.setProperty("password","");
Driver d=new com.mysql.jdbc.Driver();
Connection con = d.connect(url,prop);
if(con==null) {
System.out.println("connection failed");
return;
}
DatabaseMetaData dm =con.getMetaData();
String dbversion=dm.getDatabaseProductVersion();
String dbname=dm.getDatabaseProductName();
System.out.println("name:"+dbname);
System.out.println("version:"+dbversion);
}
}
,但它說: 「包com.mysql.jdbc」 並不存在。 P.S. :我在Windows XP平臺上使用NetBeans 7.2.x IDE
您是否有可用於編譯器和類路徑的軟件包?答案肯定是否定的。 – thatidiotguy
是的,我已經將它添加到類路徑 – dhpratik