楼主你应该先通过jdbc驱动程序得到一个数据库的连接Connection。
Statement statement = connection.createStatement();
这段代码能够看出你的connection是没有被定义没有被初始化,不信你贴出你的代码看看。

解决方案 »

  1.   

    mysql版本和驱动的版本要匹配,换个驱动试试
      

  2.   

    把你的Connection connection 的定义放在try,catch的外面
    Connection connection = null;
    try{
      ...
    }catch(..) {
      ...
    }
    你如果放在try,catch里面,connection就只在这个try,catch里面有效
      

  3.   

    Connection connection=DriverManager.getConnection(url);这一句应该换成:
    Connection connection=DriverManager.getConnection(url,user,password);
      

  4.   

    看错误可知是找不到connection的定义,原因是Connection connection=DriverManager.getConnection(url);放在了第一个try、catch里了,可以这样改,先在try、catch外定义Connection connection=null;然后再将原先的Connection connection=DriverManager.getConnection(url);放到第二个try、catch里并去掉Connection即connection=DriverManager.getConnection(url);就可
      

  5.   

    问题已解决。。经过几次配置发现只要把mysql-connector-java-3.1.10-bin.jar拷贝至:
    tomcat的common\lib,就可以了,考完之后需要重新启动tomcat