Created
September 21, 2016 15:42
-
-
Save donkarlo/6462c95d0eef566329d0b15a700c7870 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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