Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package com.test;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- import java.util.ArrayList;
- import javax.ws.rs.GET;
- import javax.ws.rs.Path;
- import javax.ws.rs.Produces;
- import javax.ws.rs.core.MediaType;
- /**
- *
- * @author ramiro
- */
- @Path("usuarioscontroller")
- public class UsuariosController {
- @GET
- @Path("/getData")
- @Produces(MediaType.APPLICATION_JSON)
- public ArrayList<testModel> getDataInJSON() throws ClassNotFoundException, SQLException
- {
- ArrayList<testModel> tmm=new ArrayList<>();
- Connection con=null;
- String username="planseguro";
- String password="NzFjMzUzZW";
- String query="select * from Usuarios";
- Class.forName("com.mysql.jdbc.Driver");
- con=DriverManager.getConnection("jdbc:mysql://localhost:3306/planseguro",username,password);
- Statement st=con.createStatement();
- ResultSet rs=st.executeQuery(query);
- while(rs.next())
- {
- testModel tm=new testModel();
- tm.setId(rs.getInt("Id"));
- tm.setName(rs.getString("Usuario"));
- tm.setEmail(rs.getString("Clave"));
- tmm.add(tm);
- }
- return tmm;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement