修改数据库表出错 高手看下哦

zl4460072 2009-09-22 08:09:53
代码如下
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("连接数据库出错!");
}
提示的错误是 连接数据库出错
哪个地方写的不对阿?
...全文
39 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
zilong4460072 2009-09-22
  • 打赏
  • 举报
回复
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();
}
}
}
}
}

62,621

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧