import java.sql.*;
public class connectMySQL
{
public static void mian(String args[])
{
String driver="org.mm.mysql.Driver";
String url="jdbc:mysql://localhost:3360/mysql?";
String user="root";
String password="";
try
{
Class.forName(driver);
}
catch(Exception e)
{
System.out.println("无法加载驱动程序:"+driver);
}
try
{
Connection con=DriverManager.getConnection(url,user,password);
if(!con.isClosed())
System.out.println("数据库连接成功!");
con.close();
}
catch(SQLException ee)
{
//System.out.println("数据库连接失败!");
System.out.println(ee.getMessage());
}
}
}
这些代码有什么错误啊?

解决方案 »

  1.   

    有,首先驱动错了,org.gjt.mm.mysql.Driver
      

  2.   

    String driver="org.mm.mysql.Driver";//这句写错了。应该是com.mysql.jdbc.Driver
      

  3.   

    错误是:Data source rejected establishment of connection,  message from server: "Host 'b
    illgates' is not allowed to connect to this MySQL server"
    Press any key to continue...
      

  4.   

    你没有指明要连接MySql里的哪个库。给你一个我连接的例子:
    conn = DriverManager.getConnection("jdbc:mysql://localhost/EP?user=root&password=qqdiy0&useUnicode=true&characterEncoding=gbk"); EP是库名 
      

  5.   

    端口好像不对,去掉端口号使用默认端口!
    另外,是main不是mian!String driver="com.mysql.jdbc.Driver";在我的机子上通过,我的没mysql-jdbc是3.11。
      

  6.   

    Class.forName("org.gjt.mm.mysql.Driver").newInstance(); 
    String url ="jdbc:mysql://localhost/softforum?user=soft&password=soft1234&useUnicode=true&characterEncoding=8859_1" 
    //testDB为你的数据库名 
    Connection conn= DriverManager.getConnection(url); 
    Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE); 
    String sql="select * from test"; 
    ResultSet rs=stmt.executeQuery(sql); 
    while(rs.next()) {%> 
    您的第一个字段内容为:<%=rs.getString(1)%> 
    您的第二个字段内容为:<%=rs.getString(2)%>
      

  7.   

    String url="jdbc:mysql://localhost:3360/mysql?";
    你的数据库名是“mysql?”???如果数据库名是“mysql”那是不用“?”的。