Advertisement
Guest User

Untitled

a guest
Jun 30th, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.49 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package com.test;
  7.  
  8. import java.sql.Connection;
  9. import java.sql.DriverManager;
  10. import java.sql.ResultSet;
  11. import java.sql.SQLException;
  12. import java.sql.Statement;
  13. import java.util.ArrayList;
  14. import javax.ws.rs.GET;
  15. import javax.ws.rs.Path;
  16. import javax.ws.rs.Produces;
  17. import javax.ws.rs.core.MediaType;
  18.  
  19. /**
  20.  *
  21.  * @author ramiro
  22.  */
  23. @Path("usuarioscontroller")
  24.  
  25. public class UsuariosController {
  26.     @GET
  27.     @Path("/getData")
  28.     @Produces(MediaType.APPLICATION_JSON)
  29.     public ArrayList<testModel> getDataInJSON() throws ClassNotFoundException, SQLException
  30.     {
  31.         ArrayList<testModel> tmm=new ArrayList<>();
  32.         Connection con=null;
  33.         String username="planseguro";
  34.         String password="NzFjMzUzZW";
  35.         String query="select * from Usuarios";
  36.         Class.forName("com.mysql.jdbc.Driver");
  37.         con=DriverManager.getConnection("jdbc:mysql://localhost:3306/planseguro",username,password);
  38.         Statement st=con.createStatement();
  39.         ResultSet rs=st.executeQuery(query);
  40.         while(rs.next())
  41.         {
  42.             testModel tm=new testModel();
  43.             tm.setId(rs.getInt("Id"));
  44.             tm.setName(rs.getString("Usuario"));
  45.             tm.setEmail(rs.getString("Clave"));  
  46.             tmm.add(tm);
  47.         }
  48.  
  49.         return tmm;
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement