SQL method for login

Asked

Viewed 138 times

4

I have the following scheme:

JdbcRowSet myrs = new JdbcRowSetImpl();

myrs.setUrl("jdbc:postgresql://localhost:9999/teste");
myrs.setUsername("postgres");
myrs.setPassword("");
myrs.setCommand("select count (*) from pessoas where cpf = '12345'");
myrs.execute();

ResultSetMetaData md = myrs.getMetaData();
String columncount = //Exemplo: getColumnName(1);

if ( columncount == 12345){
    return ("existe");  
} if ( columncount != 12345){
    return ("inexiste");
}

Does anyone know the method that would apply instead of the /Example to capture the contents of the "Cpf" column for confirmation of the existence of Cpf "12345"?

1 answer

3

  • Hello, @bupereira. Welcome to [pt.so]! Really the getString is a way out. Probably the use of ResultSetMetaData is just a misunderstanding. However, as the query returns the count of records, I think it would be best to use the getInt to assign to an integer variable and to if check if more than one record: if (count > 0).

  • Thanks for the answers, but it’s not working >.<

  • You get some mistake?

  • I posted the error as an answer to better read, follows below:

  • 1

    I did it! I did the following: Jdbcrowset myrs = new Jdbcrowsetimpl(); myrs.setUrl("jdbc:postgresql://localhost:9999/test"); myrs.setUsername("postgres"); myrs.setPassword("); myrs.setCommand("select * from people"); myrs.execute(); ; }

  • Ball show! Just score there as solved and let’s go next!

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.