如何用Java 获得 使用sql 语句 select 受影响的行数?
publicstaticintNewRegister(Stringa,Stringb){intmystate=1;intstate=-1;try{Connectionco...
public static int NewRegister(String a,String b)
{
int mystate=1;
int state=-1;
try {
Connection conn = connect.Getconnection("sql2005db.ini");
//String sql = "select snum,password from MyJavaDB";
String sql = "select * from student where snum = '"+a+"' and password = '"+b+"'";
PreparedStatement st = conn.prepareStatement(sql);
ResultSet rs= st.executeQuery();
// Statement st = conn.createStatement();
//int num = st.executeUpdate(sql);
if()
{
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {new JFrameregister().setVisible(true);}});
}
else if() mystate = 0;
//rs.close();
conn.close();
} catch (Exception ex) {
Logger.getLogger(register.class.getName()).log(Level.SEVERE, null, ex);
}
return mystate;
}
PS:用受影响的行数,来判断if/else if 语句。 展开
{
int mystate=1;
int state=-1;
try {
Connection conn = connect.Getconnection("sql2005db.ini");
//String sql = "select snum,password from MyJavaDB";
String sql = "select * from student where snum = '"+a+"' and password = '"+b+"'";
PreparedStatement st = conn.prepareStatement(sql);
ResultSet rs= st.executeQuery();
// Statement st = conn.createStatement();
//int num = st.executeUpdate(sql);
if()
{
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {new JFrameregister().setVisible(true);}});
}
else if() mystate = 0;
//rs.close();
conn.close();
} catch (Exception ex) {
Logger.getLogger(register.class.getName()).log(Level.SEVERE, null, ex);
}
return mystate;
}
PS:用受影响的行数,来判断if/else if 语句。 展开
推荐于2016-09-21
展开全部
rs.last();
int rowCount = rs.getRow();
或者
int rowCount = 0;
while(rset.next()) {
rowCount++;
}
其实,如果你只要行数,不要其他东西,改一下sql就行了
String sql = "select count(*) from student where snum = '"+a+"' and password = '"+b+"'";
直接查询行数
int rowCount = 0;
if(rset.next()) {
rowCount=rset .getInt(1); // 这里是0还是1 忘了
}
int rowCount = rs.getRow();
或者
int rowCount = 0;
while(rset.next()) {
rowCount++;
}
其实,如果你只要行数,不要其他东西,改一下sql就行了
String sql = "select count(*) from student where snum = '"+a+"' and password = '"+b+"'";
直接查询行数
int rowCount = 0;
if(rset.next()) {
rowCount=rset .getInt(1); // 这里是0还是1 忘了
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询