- package com.test;
- import com.connection.SingleConnection;
- import com.model.entities.Usuario;
- import java.sql.Connection;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- public class Test {
- public static void main(String[] args){
- Connection conexao = SingleConnection.getConnection();
- List<Usuario> userList = new ArrayList<Usuario>();
- try {
- PreparedStatement st = conexao.prepareStatement("SELECT * FROM usuarios");
- ResultSet rs = st.executeQuery();
- while (rs.next()){
- Usuario usuario = new Usuario();
- usuario.setId(rs.getInt("id"));
- usuario.setNome(rs.getString("nome"));
- usuario.setEmail(rs.getString("email"));
- userList.add(usuario);
- }
- for (Usuario usuario : userList) {
- System.out.print(usuario);
- }
- SingleConnection.closeResultSet(rs);
- SingleConnection.closeStatement(st);
- SingleConnection.closeConnection();
- } catch (SQLException ex) {
- }
- }
- }
[text] test
Viewer
*** This page was generated with the meta tag "noindex, nofollow". This happened because you selected this option before saving or the system detected it as spam. This means that this page will never get into the search engines and the search bot will not crawl it. There is nothing to worry about, you can still share it with anyone.
Editor
You can edit this paste and save as new: