import java.sql.*;
import com.mysql.jdbc.ResultSet;
import com.mysql.jdbc.Statement;
import com.mysql.jdbc.Driver;/**
*
* @author Administrator
*/
public class SelectDB {
/** Creates a new instance of SelectDB */
public static void main(String[] args) {
try
{
Class.forName(" com.mysql.jdbc.Driver");
}
catch (java.lang.ClassNotFoundException e)
{
System.out.print("Class not found exception occur. Message is:");
System.out.print(e.getMessage());
}
try
{
Statement stmt;
ResultSet rs;
String url = "jdbc:mysql://localhost:3306/DWDM";
String user = "root";
String passwordofDB = "lm";
Connection conn = null;
try
{
conn = DriverManager.getConnection(url,user,passwordofDB);
}
catch(Exception ex)
{
ex.printStackTrace();
}
stmt =(Statement) conn.createStatement();
rs = (ResultSet) stmt.executeQuery("select* from user");
while (rs.next())
{
String id =rs.getString(1);
String password = rs.getString(2);
int access=rs.getInt(3);
String introduction= rs.getString(4);
System.out.println("id:"+id);
System.out.println("password:"+password);
System.out.println("access:"+access);
System.out.println("introduction:"+introduction);
}
rs.close();
stmt.close();
conn.close();
}
catch(SQLException e)
{
System.out.print("SQL Exception occur.Message is:");
System.out.print(e.getMessage());
}
}
}
我mysql的版本是4.1,驱动安装了mysql-connector-java 3.1.7.jar,并且在NetBeans中用数据库管理界面已经连接成功,说明驱动没有错,在类路径中已经.jar文件怎么还会报下面错呢,希望大牛们能指点,跪谢!
java.sql.SQLException: No suitable driver at java.sql.DriverManager.getConnection(DriverManager.java:532) at java.sql.DriverManager.getConnection(DriverManager.java:171) at SelectDB.main(SelectDB.java:44)java.lang.NullPointerException at SelectDB.main(SelectDB.java:51)Exception in thread "main" Class not found exception occur. Message is: com/mysql/jdbc/Driver
import com.mysql.jdbc.ResultSet;
import com.mysql.jdbc.Statement;
import com.mysql.jdbc.Driver;/**
*
* @author Administrator
*/
public class SelectDB {
/** Creates a new instance of SelectDB */
public static void main(String[] args) {
try
{
Class.forName(" com.mysql.jdbc.Driver");
}
catch (java.lang.ClassNotFoundException e)
{
System.out.print("Class not found exception occur. Message is:");
System.out.print(e.getMessage());
}
try
{
Statement stmt;
ResultSet rs;
String url = "jdbc:mysql://localhost:3306/DWDM";
String user = "root";
String passwordofDB = "lm";
Connection conn = null;
try
{
conn = DriverManager.getConnection(url,user,passwordofDB);
}
catch(Exception ex)
{
ex.printStackTrace();
}
stmt =(Statement) conn.createStatement();
rs = (ResultSet) stmt.executeQuery("select* from user");
while (rs.next())
{
String id =rs.getString(1);
String password = rs.getString(2);
int access=rs.getInt(3);
String introduction= rs.getString(4);
System.out.println("id:"+id);
System.out.println("password:"+password);
System.out.println("access:"+access);
System.out.println("introduction:"+introduction);
}
rs.close();
stmt.close();
conn.close();
}
catch(SQLException e)
{
System.out.print("SQL Exception occur.Message is:");
System.out.print(e.getMessage());
}
}
}
我mysql的版本是4.1,驱动安装了mysql-connector-java 3.1.7.jar,并且在NetBeans中用数据库管理界面已经连接成功,说明驱动没有错,在类路径中已经.jar文件怎么还会报下面错呢,希望大牛们能指点,跪谢!
java.sql.SQLException: No suitable driver at java.sql.DriverManager.getConnection(DriverManager.java:532) at java.sql.DriverManager.getConnection(DriverManager.java:171) at SelectDB.main(SelectDB.java:44)java.lang.NullPointerException at SelectDB.main(SelectDB.java:51)Exception in thread "main" Class not found exception occur. Message is: com/mysql/jdbc/Driver
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货