Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package giojejjere;
- import javax.annotation.PostConstruct;
- //import javax.activation.DataSource;
- import javax.annotation.Resource;
- import javax.ws.rs.*;
- import javax.ws.rs.GET;
- import javax.ws.rs.Path;
- import javax.ws.rs.core.Context;
- import jdk.nashorn.internal.objects.annotations.Getter;
- import java.sql.*;
- import javax.sql.*;
- //@Resource(name="mariadb",lookup="jboss/mariadb");
- @Path("service")
- public class orafoRest{
- @Resource(lookup="java:/PostgresXADS") private DataSource ds;
- private Connection conn;
- /*
- String url = "jdbc:postgresql://127.0.0.1:5433/test";
- Connection conn;
- */
- String error = "";
- public RestService(){
- try {
- //DriverManager.registerDriver(new com.mariadb.jdbc.Driver ());
- //Class.forName("com.postgresql.jdbc.Driver").newInstance();
- //conn = DriverManager.getConnection(url,"root","root");
- //error = "connesso";
- } catch (Exception e) {
- error = e.getMessage();
- }
- }
- @GET
- @Path("insertneworder/{details}/{type_id}/{size}/{quantity}/{price}")
- public String insert_record(@PathParam("details") String cusDet,
- @PathParam("type_id") int type_id,
- @PathParam("size") int size,
- @PathParam("quantity") int quantity,
- @PathParam("price") int price){
- try {
- conn = ds.getConnection();
- String insertNewUserSQL = "INSERT INTO \"customerOrder\" "+
- "(orderDetails, type_id, size, quantity, price)"+
- "VALUES (?, ?, ?, ?, ?)";
- PreparedStatement pstmt = conn.prepareStatement(insertNewUserSQL);
- pstmt.setString(1, cusDet);
- pstmt.setInt(2,type_id);
- pstmt.setInt(3,size);
- pstmt.setInt(4,quantity);
- pstmt.setInt(5,price);
- pstmt.executeUpdate();
- return "<h1>DONE</h1>";
- }catch (Exception e){
- return "<h1> an error has occurred : <br>"+e.getMessage()+"</h1>";
- }
- }
- @GET
- @Path("getbaseprice/{type_id}")
- public String show_users(@PathParam("type_id") int id){
- String getBasePriceSQL = "SELECT * FROM TypePrice WHERE \"type_id\" = "+id;
- //\"basePrice\"
- try{
- conn = ds.getConnection();
- Statement t = conn.createStatement();
- ResultSet rs = t.executeQuery(getBasePriceSQL);
- String tmp="<table>";
- while (rs.next()) {
- tmp+="<tr>";
- tmp+="<td>"+rs.getInt("type_id")+"</td>";
- tmp+="<td>"+rs.getInt("basePrice")+"</td>";
- tmp+="</tr>";
- }
- tmp+="</table>";
- return tmp;
- }catch (Exception e){
- return e.getMessage();
- }
- }
- @GET
- @Path("getsizemultiplier/{size}")
- public String sayHello(@PathParam("size") int s) {
- String tmp = "";
- try {
- conn = ds.getConnection();
- Statement t = conn.createStatement();
- ResultSet rs = t.executeQuery("SELECT multiplier FROM \"user\" WHERE size = "+s);
- while (rs.next()) {
- String txt = rs.getInt("multiplier")+"<br/>";
- System.out.println(txt);
- tmp += txt;
- }
- } catch (Exception e) {
- error+=e.getMessage();
- }
- return "<h1>"+error+" -- "+tmp+"</h1>";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement