一个Java数据库驱动程序的问题

来源:百度知道 编辑:UC知道 时间:2024/06/22 05:05:25
正在学习MySQL,按照书上的例子谢了代码,如下:

import java.sql.*;
public class Hello {
Connection connection;
private void displaySQLErrors(SQLException e){
System.out.println("SQLException: "+e.getMessage());
System.out.println("SQLState: "+e.getSQLState());
System.out.println("VendorError: "+e.getErrorCode());
}

public Hello(){
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
System.out.println("Driver has been found");
}catch(Exception e){
System.out.println("JDBC Driver error");
}

}

public void connectToDB(){
try{
connection=DriverManager.getConnection("jdbc:mysql//localhost:3306/test","root","root");
}
catch(SQLException e){
displaySQLErrors(e);
}
}

public void executeSQL(){
try{
Statem

我晕,我也看了会,不亲自试验还是不行,人的眼睛不行啊。哈哈
("jdbc:mysql//localhost:3306/test","root","root");
中间那块应该是 mysql://loaclhost 掉了个引号造成的!!!
赶紧给分,哈哈

("jdbc:mysql://localhost:3306 /test","root","root");

自己看看32行是什么,空指针太好找了