Tady to je:
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con = DriverManager.getConnection("jdbc:mysql://localhost/t", "", "");
Statement st = con.createStatement();
String sql = ("SELECT * FROM posts ORDER BY id DESC LIMIT 1;");
ResultSet rs = st.executeQuery(sql);
if(rs.next()) {
int id = rs.getInt("first_column_name");
String str1 = rs.getString("second_column_name");
}
con.close();
V rs.getInt nebo rs.getString můžete předat column_id počínaje 1 , ale raději předám column_name je to více informativní, protože se nemusíte dívat do databáze table pro který index je co column .
AKTUALIZACE: rs.next