Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SQL

How To Execute SQL Select Statements

// jdbc select from
PreparedStatement selectStatement = connection.prepareStatement("select * from users where first_name =  ?");
selectStatement.setString(1, "John");

// this will return a ResultSet of all users with said name
ResultSet rs = selectStatement.executeQuery();

// will traverse through all found rows
while (rs.next()) {
    String firstName = rs.getString("first_name");
    String lastName = rs.getString("last_name");
    System.out.println("firstName = " + firstName + "," + "lastName= " + lastName );
}
Source by www.marcobehler.com #
 
PREVIOUS NEXT
Tagged: #How #To #Execute #SQL #Select #Statements
ADD COMMENT
Topic
Name
3+1 =