Skip to content

Instantly share code, notes, and snippets.

@donkarlo
Created September 21, 2016 15:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save donkarlo/6462c95d0eef566329d0b15a700c7870 to your computer and use it in GitHub Desktop.
Save donkarlo/6462c95d0eef566329d0b15a700c7870 to your computer and use it in GitHub Desktop.
package module.concept.home.webservice.jaxrs.jersey;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Response;
import config.data.MainDb;
import java.io.IOException;
import java.sql.SQLException;
import module.concept.home.Home;
@Path("/home")
public class HomeService {
@POST
@Path("/insert")
@Produces("application/json")
public Response insert(String jsonedHome) throws IOException, SQLException, ClassNotFoundException {
Home home = new Home(jsonedHome);
this.insert(home);
return Response.status(201).entity(jsonedHome).build();
}
public void insert(Home home) throws SQLException, ClassNotFoundException {
Connection connection = MainDb.getInst().getConnection();
PreparedStatement pstmt = connection.prepareStatement("INSERT INTO homes(exchangingStrategy,value,location)"
+ " VALUES(" + home.getExchangingStrategy() + "," + home.getValue() + "," + home.getLocation() + ")");
ResultSet rs = pstmt.executeQuery();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment