Answer the question
In order to leave comments, you need to log in
JAVA JDBC unable to get single record from table?
Hello everyone, if the query returns several records, then everything is fine, but if one record is returned, then it is impossible to get it. Tell me what's the problem?
Statement stmt = dbConnent.getCon().createStatement();
//Возвращает одну запись (CA3896D8-46C9-49EA-A94B-7E5B3CE8721C,belov_aa)
String sql = "SELECT TOP(1) Id AS UID,Name AS NAME FROM SysAdminUnit WHERE Name='belov_aa'";
System.out.println(sql);
ResultSet rs = stmt.executeQuery(sql);
while (rs.next()) {
String name = rs.getString("NAME");
String uid = rs.getString("UID");
System.out.println(uid+":"+name);
}
Answer the question
In order to leave comments, you need to log in
Try:
if (rs.next())
{
String name = rs.getString("NAME");
String uid = rs.getString("UID");
System.out.println(uid+":"+name);
}
In such cases, I write something like this
if (rs.next())
{
do{
................................
} while (rs.next());
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question