小学生光荣榜板面设计:java 的问题

来源:百度文库 编辑:高考问答 时间:2024/05/04 19:49:45
连接数据库失败!!!
======================
代码:
======================
package beans;

import java.sql.*;

public class Condb{
String dbname="jdbc:mysql://127.0.0.1:3306/music";
ResultSet rs=null;
Connection con=null;
Statement stmt=null;
public Condb(){
try{
Class.forName("com.mysql.jdbc.Driver");
}catch(ClassNotFoundException e1){
System.err.println(e1);
}try{
con=DriverManager.getConnection(dbname);
}catch(SQLException e3){
System.err.print(e3);
}
}public ResultSet executeQuery(String sql){
try{
stmt=con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
rs=stmt.executeQuery(sql);
}catch(SQLException e2){
System.err.print(e2);
}
return rs;
}public int excuteUpdate(String sql){
int rt=0;
try{
stmt=con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
rt=stmt.executeUpdate(sql);
}catch(SQLException ex){
System.err.print(ex);
}
return rt;
}public void close(){
try{
if(con!=null)
con.close();
}catch(Exception e){
System.out.print(e);
}try{
if(rs!=null)
rs.close();
}catch(Exception e){
System.out.println(e);
}
}
}
=======================

有没有什么问题
连接不到数据库

错误信息?

连接数据库的用户名和密码.
把错误信息打出来

String dbname="jdbc:mysql://127.0.0.1:3306/music";

3306这个端口号可以吗?

本机可以不用用户名和密码,

把错误原因写出来,才能知道怎么解决阿!