连接数据库问题!急!!!

sky_1989 2007-12-25 06:24:03
import java.sql.*;
class xuexi
{
public static void main(String[]args)
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url="jdbc:odbc:sky";
Connection con=DriverManager.getConnection(url);
Statement s=con.createStatement();
ResultSet rs=s.executeQuery("delete from a where class='5'");
s.close();
rs.close();
s=con.createStatement();
rs=s.executeQuery("delete from b where name='aa'");
rs=s.executeQuery("delete from a where class='s203'");
}catch(ClassNotFoundException e)
{
System.out.println(e);
}catch(SQLException e)
{
System.out.println(e);
}
}
}
为什么这两个语句只执行完第一个后,第二个就不执行了呢??如果想让它执行完第一个后继续执行第二个要怎么修改才可以
(如果有第三个表需要删除的话继续删除下一个),高手帮帮我啊
rs=s.executeQuery("delete from b where name='aa'");
rs=s.executeQuery("delete from a where class='s203'");
...全文
87 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
lc231375316 2007-12-26
  • 打赏
  • 举报
回复
public ResultSet reset(String sql)
{
try{
Connection con;
Statement s=con.createStatement();
ResultSet rs=s.executeQuery(sql);
return rs;
}

}

catch(Exception e){
e.printStackTrace();
}
return null;
}

public static void main(String[] args){
DB db=new DB();
db.reset("delete from [a] where name='aaa'");
}
sky_1989 2007-12-26
  • 打赏
  • 举报
回复
结贴
sky_1989 2007-12-26
  • 打赏
  • 举报
回复
1楼跟3楼说的对,不过要把rs转换正int型的
谢谢了
老紫竹 2007-12-26
  • 打赏
  • 举报
回复
你确认没有抛出异常吗?
}catch(SQLException e)
{
System.out.println(e); /// 你的控制台没有任何输出??
}
}
wusilou 2007-12-26
  • 打赏
  • 举报
回复
executeQuery是用来查询时用的select *
wxinb 2007-12-26
  • 打赏
  • 举报
回复
你的程序写错了啊!改正结果:
rs=s.executeQuery("delete from b where name='aa'"); ==>
rs=s.executeUpdate("delete from b where name='aa'");
rs=s.executeQuery("delete from a where class='s203'");==>
rs=s.executeUpdate("delete from a where class='s203'");

这样就行。

DELETE,CREATE,UPDATE用executeUpdate操作;
SELECT用executeQuery操作;
newflypig 2007-12-25
  • 打赏
  • 举报
回复
你试试用s.executeUpdate("");语句看看,一般delete等无结果集返回的sql语句用Update效率比较高

62,623

社区成员

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

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