java数据库连接错误求助

来源:百度知道 编辑:UC知道 时间:2024/05/15 23:21:53
我用的数据库为MySQL,数据库名为tushuguanli 密码为123,运行显示
IWAV0048I Java Bean shujuku started with null constructor
数据库连接失败!
请问为什么不显示"数据库连接成功!"哪里出错了。
import java.sql.*;

public class shujuku
{
private String driverName = "com.mysql.jdbc.Driver" ;
private String url = "jdbc:mysql://localhost:3306/tushuguanli" ;
private String user = "root" ;
private String password = "123" ;
private Connection conn = null ;

public shujuku()
{
try
{
Class.forName(driverName) ;
this.conn = DriverManager.getConnection(url,user,password) ;
System.out.println("数据库连接成功!") ;
}
catch (Exception e)
{
System.out.println("数据库连接失败!") ;
}
}
public Connection getConnection()
{
return this.conn ;
}
public void close()
{
try
{
this.conn.close

13.MySQL数据库
//import java.sql.*;
//String url ="jdbc:mysql://localhost/myDB?user=soft&password=soft1234&useUnicode=true&characterEncoding=8859_1";
String url ="jdbc:mysql://localhost:3306/myDB";
//myDB为数据库名
Connection conn= DriverManager.getConnection(url,"root","root");
Statement stmtNew=conn.createStatement();

catch (Exception e)
{
e.printStackTrace();
System.out.println("数据库连接失败!") ;
}
改成这样,然后把控制台信息贴出来

看你起那垃圾名字~