代码如下
try
{
sql="update student set age='"+Age+"',cla='"+Cla+"' where stuName='"+Name+"'";
conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/management","root","4460072");
stm=conn.createStatement();
rs=stm.executeQuery(sql);
if(rs.next())
{
JOptionPane.showMessageDialog(null, "修改成功!");
}
}
catch(SQLException ee)
{
System.out.println("连接数据库出错!");
         }
提示的错误是 连接数据库出错   
哪个地方写的不对阿?

解决方案 »

  1.   

    try
    {
    Class.forName("com.mysql.jdbc.Driver");
    }
    catch(ClassNotFoundException ee)
    {
    System.out.println("加载数据库驱动程序出错!");
    }
    try
    {
    conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/management","root","4460072");
    stm=conn.createStatement();
    rs=stm.executeUpdate(sql);
    if(rs>0)
    {
    JOptionPane.showMessageDialog(null, "修改成功!");
    }
    }
    catch(SQLException ee)
    {
    System.out.println("连接数据库出错!");
    }
     finally
      {
      if(stm!=null)
      {
      try
    {
    stm.close();
    }
    catch(SQLException ee)
    {
    ee.printStackTrace();
    }
      }
      if(conn!=null)
      {
      try
    {
    conn.close();
    }
    catch(SQLException ee)
    {
    ee.printStackTrace();
    }
      }
      }
    }
    }