Home > Back-end >  For JAVA USES JDBC to connect to the database, while (rs), next ()) cycle number is not complete
For JAVA USES JDBC to connect to the database, while (rs), next ()) cycle number is not complete

Time:04-09

is the name of the database query, account privileges enough, while (rs), next () loop, sometimes does not enter circulation
Check the data of less


 
/* *
* query library name
*
* @ return
*/
Public List GetLibList () {
List Result=new ArrayList ();
Try {
String SQL="select SCHEMA_NAME from information_schema. Schemata";
//create the SQL statement execution,
PreparedStatement ps=conn. PrepareStatement (SQL);
The ResultSet rs=ps. ExecuteQuery ();
();//the ResultSetMetaData rs_metaData=https://bbs.csdn.net/topics/rs.getMetaData
While (rs), next ()) {
String a=new String ();
SCHEMA_NAME a=rs. Get string (" ");
Result. The add (a);
}
return result;
} the catch (Exception e) {
return result;
}
}

CodePudding user response:

For example: there are ten data, can only be found out seven, skip cycle three times

CodePudding user response:

But his odds swallow exceptions is not a good habit
} the catch (Exception e) {
e.printStackTrace();
return result;
}

And see whether the fault database

CodePudding user response:

You don't have a skip this code, circulation situation,
If the rs. Next () returns false, the loop is directly over, how can skip?
If the rs. Next () returns true, it will enter the loop body, since entered the loop body, must not skip the circulation situation,

In addition, the abnormal no processing, code of swallow exceptions, are the least desirable, when the application problems, swallow exceptions will increase the difficulty of the problem screening,

The original poster of the code, the most likely reason why there are two problems:
1. Program to connect account permissions not to complete, so the query data may not be full; (of course, the original poster said permissions tube is enough, that's not to consider)
2. In the process of circulation throws exceptions, for example, circulation article 8 data when an exception is thrown, then the exception is swallowed, directly back to the seven records,

CodePudding user response:

reference, 3/f ice rain response:
you this code, there is no skip circulation situation,
If the rs. Next () returns false, the loop is directly over, how can skip?
If the rs. Next () returns true, it will enter the loop body, since entered the loop body, must not skip the circulation situation,

In addition, the abnormal no processing, code of swallow exceptions, are the least desirable, when the application problems, swallow exceptions will increase the difficulty of the problem screening,

The original poster of the code, the most likely reason why there are two problems:
1. Program to connect account permissions not to complete, so the query data may not be full; (of course, the original poster said permissions tube is enough, that's not to consider)
2. In the process of circulation throws exceptions, for example, circulation article 8 data when an exception is thrown, then the exception is swallowed, directly back to the seven records,
I agree with the second point, just write Java don't know much about, tomorrow to work in the study

CodePudding user response:

refer to the second floor nayi_224 response:
but his odds swallow exceptions is not a good habit to
} the catch (Exception e) {
e.printStackTrace();
return result;
}

And see whether the fault database
no problem of database connection, in another database or so, so try it tomorrow
  • Related