Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'Cliente',
- 'CREATE TABLE `cliente` (
- `ClientId` int(11) NOT NULL,
- `ApellidoPaterno` varchar(255) NOT NULL,
- `ApellidoMaterno` varchar(255) DEFAULT NULL,
- `Nombre` varchar(255) DEFAULT NULL,
- `Telefono` mediumtext,
- `Username` varchar(255) NOT NULL,
- PRIMARY KEY (`ClientId`)
- )
- ENGINE=InnoDB DEFAULT CHARSET=utf8'
- package me.jmll.utm.config;
- import java.sql.*;
- public class Conexion{
- public Connection getConexion(){
- Connection con = null;
- try {
- Class.forName("com.mysql.jdbc.Driver");
- con = DriverManager.getConnection(
- "jdbc:mysql://localhost:3306/miscelanialabety","root","Patito01");
- return con;
- }
- catch(Exception e){
- try {throw e;}
- catch (Exception e1) { e1.printStackTrace();}}
- return con;
- }
- }
- @Override
- public List<Cliente> getClientes() {
- String sql = "SELECT * FROM Cliente";
- try {
- conexion = new Conexion().getConexion();
- PreparedStatement ps = conexion.prepareStatement(sql);
- Cliente cliente = null;
- List<Cliente> listaClientes = new ArrayList<Cliente>();
- ResultSet rs = ps.executeQuery();
- while (rs.next()) {
- cliente = new Cliente(
- rs.getInt(1),
- rs.getString("ApellidoPaterno"),
- rs.getString("ApellidoMaterno"),
- rs.getString("Nombre"),
- rs.getLong("Telefono"),
- rs.getString("Username")
- );
- listaClientes.add(cliente);
- }
- rs.close();
- ps.close();
- return listaClientes;
- } catch (SQLException e) {
- throw new RuntimeException(e);
- } finally {
- if (conexion != null) {
- try { conexion.close();}
- catch (SQLException e) {}
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement