String url ="jdbc:mysql://localhost:3306/exc?user=root&useUnicode=true&characterEncoding=gb2312";

解决方案 »

  1.   

    可能没有安装好Jdbc-mysql 的驱动
    而且String url ="jdbc:mysql://localhost/excuser=root&useUnicode=true&characterEncoding=gb2312";
    好像没必要这样写吧?
      

  2.   

    给你一个连接MySQL的类:
    <%@page import="java.sql.*"%>
    <%!
    /*
    该文件用于处理Mysql数据库,提供连接,执行得方法
    [1]初始化类时设置Mysql参数 mysql(String db,String user,String pwd)
    使用省缺用户和密码 mysql(String db)
    全部省缺,省缺数据库为 mysql,用户 root 密码 ""
    [2]重设数据库参数 setDatabase(String db,String user,String pwd)
    [3]执行SQL命令
    a、boolean execute(String sql,int type)
    type参数为3时,执行查SQL查询命令,成员变量
    Connection con
    Statement smt
    ResultSet res
    均被改变
    type参数为2时,执行SQL更新,删除,插入操作,成员变量
    Connection con
    Statement smt
    被改变
    b、boolean execute(String sql)
    执行查SQL查询命令,成员变量
    Connection con
    Statement smt
    ResultSet res
    均被改变
    [4]关闭连接
    void close(Connection conn,Statement smtt,ResultSet ress)
    关闭查询操作
    void close(Connection conn,Statement smtt)
    关闭更新操作
    */
    public class mysql
    {
    String defaultdb="mysql";
    String driver="org.gjt.mm.mysql.Driver";
    String url="jdbc:mysql://localhost:3306/";
    String user="root";
    String pwd="";
    Connection con=null;
    Statement smt=null;
    ResultSet res=null;
    mysql(String db,String user,String pwd)
    {
           this.url=url+db;
           this.user=user;
           this.pwd=pwd;
    }
    mysql(String db) {this.url=this.url+db;}
    mysql() {this.url=this.url+this.defaultdb;}
    void load_driver()
    {
            try
            {
                  Class.forName(this.driver);
            }
            catch(Exception E)
            {
                  E.printStackTrace(); 
            }
    }    
    boolean execute(String sql,int type)
    {
          this.load_driver();
          try
          {
               con=DriverManager.getConnection(this.url,this.user,this.pwd);
               if(type==3){
                       smt=con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
                       res=smt.executeQuery(sql);
               }
               if(type==2){
                      smt=con.createStatement();
                      smt.executeUpdate(sql);
               }
               return(true);
          }
          catch(SQLException SE)
          {
              SE.printStackTrace(); 
              return(false);
          }
    }
    boolean execute(String sql)
    {     
          this.load_driver();
          try
          {
               con=DriverManager.getConnection(this.url,this.user,this.pwd);
               smt=con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
               res=smt.executeQuery(sql);
               return(true);
          }
          catch(SQLException SE)
          {
              SE.printStackTrace();
              return(false);
          }
    }
    void setDatabase(String db,String user,String pwd)
    {
           this.url=url+db;
           this.user=user;
           this.pwd=pwd;
    }
    void close(Connection conn,Statement smtt,ResultSet ress)
    {
         try
         {
             conn.close();
             smtt.close();
             ress.close();
         }
         catch(SQLException SE)
         {
             SE.printStackTrace(); 
         }    
    }
    void close(Connection conn,Statement smtt)
    {
         try
         {
             conn.close();
             smtt.close();
         }
         catch(SQLException SE)
         {
             SE.printStackTrace(); 
         }    
    }
    }
    %>
      

  3.   

    你在命令行执行你的查询代码试试
    mysql --user root --port 3306use exc;
    select * from datum;
      

  4.   

    javax.servlet.ServletException: Cannot connect to MySQL server on localhost:3306. Is there a MySQL server running on the machine/port you are trying to connect to? (java.lang.NumberFormatException)如果你安装了mysql在本地, 启动了? 启动之后保证端口是3306吗》??
    你用bin下面的MySQLAdmin.exe还是什么 看看数据库