java操作mysql 用结果集删除,deleteRow()能执行,但数据库没变动,不知道为什么?
importjava.sql.DriverManager;importjava.sql.PreparedStatement;importjava.sql.Connecti...
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
public class ResultSetTest {
public static final String DBDRIVER="org.gjt.mm.mysql.Driver";
public static final String DBURL="jdbc:mysql://localhost:3306/study";
public static final String DBUSER="root";
public static final String DBPASS="chenxixi2006";
public static void main(String[] args)throws Exception {
// TODO Auto-generated method stub
Connection con=null;
PreparedStatement pre=null;
ResultSet rs=null;
con=DriverManager.getConnection(DBURL,DBUSER,DBPASS);
String sql="SELECT id,name,age FROM messin"+" WHERE id=?";
pre=con.prepareStatement(sql,ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
pre.setInt(1,18);
rs=pre.executeQuery();
rs.last();
rs.deleteRow();
rs.close();
pre.close();
con.close();
}
} 展开
import java.sql.PreparedStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
public class ResultSetTest {
public static final String DBDRIVER="org.gjt.mm.mysql.Driver";
public static final String DBURL="jdbc:mysql://localhost:3306/study";
public static final String DBUSER="root";
public static final String DBPASS="chenxixi2006";
public static void main(String[] args)throws Exception {
// TODO Auto-generated method stub
Connection con=null;
PreparedStatement pre=null;
ResultSet rs=null;
con=DriverManager.getConnection(DBURL,DBUSER,DBPASS);
String sql="SELECT id,name,age FROM messin"+" WHERE id=?";
pre=con.prepareStatement(sql,ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
pre.setInt(1,18);
rs=pre.executeQuery();
rs.last();
rs.deleteRow();
rs.close();
pre.close();
con.close();
}
} 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询