1 Replies - 344 Views - Last Post: 15 June 2015 - 02:52 AM

#1 panga   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 15-June 15

Getting on user input using Query Parameters in Restful Web Service

Posted 15 June 2015 - 02:11 AM

Hi. I tried to create a restful web service project. I have a database connected to my restful web service. I tried running it to my android application using wifi and it works, but my only problem here is I can't get the input using query parameter. I tried setString but it is putting exactly the name. What's wrong with my code? Is my query parameter in the wrong place?

 
package com.sample.hays;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import javax.ws.rs.QueryParam;



public class DisplayArrayConnection2
{
	
	

		public ArrayList<Objects> getUsers(Connection con, @QueryParam("username") String username) throws SQLException{
		ArrayList<Objects> UsersList = new ArrayList<Objects>();
		PreparedStatement stmt = con.prepareStatement("SELECT * FROM user where username = '" + username+ "'");
		ResultSet rs = stmt.executeQuery();
		try
		{
			while(rs.next())
			{
				Objects UsersObject = new Objects();
				
				UsersObject.setName(rs.getString("name"));
				UsersObject.setEmailaddress(rs.getString("emailaddress"));
				UsersObject.setUsername(rs.getString("username"));
				
				UsersList.add(UsersObject);
				
			}
		} catch (SQLException e)
		{		
			e.printStackTrace();
		}
		return UsersList;
		}
	}







package com.sample.hays;


import java.sql.Connection;
import java.util.ArrayList;



public class ArrayConnection2{


		public ArrayList<Objects> getUsers() throws Exception
		{
			ArrayList<Objects> UsersList = new ArrayList<Objects>();   //creating the array
			DatabaseConnection db = new DatabaseConnection();   	//trying to call the database connection
			Connection con = db.createConnection();   	//create database connection
			DisplayArrayConnection2 access = new DisplayArrayConnection2(); 
			UsersList = access.getUsers(con, null);
			return UsersList;
		}
	}




package com.sample.hays;


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;

import com.google.gson.Gson;


import javax.ws.rs.QueryParam;
@Path("/displays")

public class DisplayUser {	
		
			@GET
			@Path("/user")	
			@Produces(MediaType.APPLICATION_JSON)

		
			
			public String usersdetails()
			{
				
				String usersdetails = null;
				ArrayList<Objects> usersList = new ArrayList<Objects>();
				
				try
				{
					usersList = new ArrayConnection2().getUsers();
					Gson gson = new Gson();
					usersdetails = gson.toJson(usersList);
				} catch (Exception e)
				{
						e.printStackTrace();
				}
				return usersdetails;
			}
			
			}		



Is This A Good Question/Topic? 0
  • +

Replies To: Getting on user input using Query Parameters in Restful Web Service

#2 Atli   User is offline

  • Enhance Your Calm
  • member icon

Reputation: 4241
  • View blog
  • Posts: 7,216
  • Joined: 08-June 10

Re: Getting on user input using Query Parameters in Restful Web Service

Posted 15 June 2015 - 02:52 AM

Moved to the Android forum.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1