K
K
KtoYa2282020-05-14 18:02:28
Java
KtoYa228, 2020-05-14 18:02:28

How can I get the SQLite result?

There is a code:

Connection cn = DriverManager.getConnection(road_to_DB);
Statment st = cn.createStatment();
//сам запрос:
if(st.executeQuery("SELECT * FROM users WHERE name = 'name'") == null) {
//TODO...... 
return;
}


How to get null from table if record does NOT exist. Returns [email protected] How to get null?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Lyoshik, 2020-05-14
@KtoYa228

Try like this:

ResultSet result = st.executeQuery("SELECT * FROM users WHERE name = 'name'");
if (!result.isBeforeFirst() ) {    
   // вернулось 0 строк
}

According to documentation:

Returns:
true if the cursor is before the first row; false if the cursor is at any other position or the result set contains no rows

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question