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'");
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'");
{
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'");
}
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操作;
}catch(SQLException e)
{
System.out.println(e); /// 你的控制台没有任何输出??
}
}
谢谢了