jdbc:mysql://localhost/user=root&password=&useUnicode=true&characterEncoding=8859_1这样看看能不能连

解决方案 »

  1.   

    不行……
    一个类型的错误,只是变为
    java.sql.SQLException: General error: Incorrect database name '?user=root&password=&useUnicode=true&characterEncoding=8859_1'
      

  2.   

    getConnection("jdbc:mysql://localhost/?useUnicode=true&characterEncoding=8859_1
    ","root","")这样呢?很奇怪啊,我这边都可以哦
      

  3.   

    java.sql.SQLException: General error: Unknown database 'mysql?useUnicode=true&characterEncoding=8859_1'还是这个……
    郁闷PS:我用的是Apache Tomcat/4.1.18
      

  4.   

    不加上mysql这个数据表名还会是这样?
      

  5.   

    对,加不加都会报错
    只有getConnection("jdbc:mysql://localhost/mysql","root","")才能连接上
      

  6.   

    mysql 的数据库经常出中文问题!
      

  7.   

    怎么可能加不加都是报mysql表的错????
    重启服务器试试看?
      

  8.   

    可是我同时写的PHP脚本却可以正常访问,并显示中文
      

  9.   

    源代码:
    import java.sql.*;public class db2
    {
    static public void main(String args[])
    {
    Connection conn = null;
    Statement s = null;
    ResultSet rs = null;
    try
    {
    System.out.println("Loading JDBC driver .....");
    DriverManager.registerDriver(new org.gjt.mm.mysql.Driver());
    System.out.println("Loaded.");
    try
    {
    System.out.println("\nConnecting to MySQL ......");
    conn = DriverManager.getConnection("jdbc:mysql://localhost/mysql?useUnicode=true&characterEncoding=8859_1","root","");
    System.out.println("Connected."); try
    {
    System.out.println("\nCreating statement......");
    s = conn.createStatement();
    System.out.println("Created.");
    try
    {
    System.out.println("\nCreating resultset......");
    rs = s.executeQuery("select * from user");
    System.out.println("Created.");
    while (rs.next())
    {
    System.out.println("\n " + rs.getString(2));
    }
    }catch (Exception exce)
    {
    System.out.println("Failed.");
    exce.printStackTrace();
    }
    }catch (Exception exc)
    {
    System.out.println("Failed.");
    exc.printStackTrace();
    }
    }catch (Exception ex)
    {
    System.out.println("Failed !");
    ex.printStackTrace();
    }
    }catch (Exception e)
    {
    System.out.println("Failed .");
    e.printStackTrace();
    }
    finally
    {
    if (conn != null)
    {
    if (s != null)
    {
    if (rs != null)
    {
    try
    {
    System.out.println("\nClosing resultset......");
    rs.close();
    System.out.println("Closed.");
    }catch (Exception eR)
    {
    System.out.println("Failed.");
    }
    }
    try
    {
    System.out.println("\nClosing statement......");
    s.close();
    System.out.println("Closed.");
    }catch (Exception eS)
    {
    System.out.println("Failed.");
    }
    }
    try
    {
    System.out.println("\nClosing connection .....");
    conn.close();
    System.out.println("Closed.");
    }catch (Exception exception)
    {
    System.out.println("Failed !");
    exception.printStackTrace();
    }
    }
    }
    }
    };try语句太多:)