Skip to content

Instantly share code, notes, and snippets.

@matiasfha
Created November 13, 2014 11:18
Show Gist options
  • Save matiasfha/ffd7c54083963c0502df to your computer and use it in GitHub Desktop.
Save matiasfha/ffd7c54083963c0502df to your computer and use it in GitHub Desktop.
Statement stmt = null;
String query =
"select attr1, attr2 from TU_TABLA";
try {
stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(query);
while (rs.next()) {
String attr1 = rs.getString("attr1");
int attr2 = rs.getInt("attr2");
mijTextField.setText(attr1);
//Si lo que se busca es concatenar dos valores obtenidos de la BD
//y asignarlos a un jTextField se puede utilizar simplemente
//la concatenacion con "+" o con String.format
jTextField2.setText(String.format("%s %i",attr1,attr2));
}
} catch (SQLException e ) {
JDBCTutorialUtilities.printSQLException(e);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment