Note that there are some explanatory texts on larger screens.

plurals
  1. POResult set usage when expected one int value only
    primarykey
    data
    text
    <p>I know it is basics and probably really simple, but I'm struggling with the following situation where i want to query the database for a specific int(id in my case), but somehow i can't acces the returned data from the data set. </p> <p>I have tested the query in db managment system and it works. I get no errors/ stacks but the result of my method is always -1.(Which means it fails :( because no int has been parsed)</p> <p>code:</p> <pre><code>public int UserFactoryEngine(String n, String p){ // query for user data, validate and return Connection conn = null; try { Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance(); } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) { System.out.println("Failure intialization of the driver! "); e.printStackTrace(); } String connectionUrl = "jdbc:sqlserver://localhost:1433;" + "databaseName=BugsSurveillance;user=sa;password=1234;integratedSecurity=true;"; try { conn = DriverManager.getConnection(connectionUrl); } catch (SQLException e) { System.out.println("Failure intialization of the connection! "); e.printStackTrace(); } System.out.println("Connected... "); String sqlquery; PreparedStatement preparedStatement; ResultSet rs; try { preparedStatement = conn.prepareStatement("SELECT id FROM Users WHERE name = ? AND pass = ? ", ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); preparedStatement.setString(1, n); preparedStatement.setString(2, p); rs = preparedStatement.executeQuery(); while (rs.next()){ System.out.println(rs.getInt(1)); } } catch (SQLException e) { System.out.println("Prepared statement failure!"); e.printStackTrace(); } return -1; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload