Back to project page foodroid.
The source code is released under:
GNU General Public License
If you think the Android project foodroid listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
/* * To change this template, choose Tools | Templates * and open the template in the editor./*from www . j ava 2 s. c om*/ */ package com.wmc.Registration; import java.sql.*; import javax.ws.rs.PathParam; import javax.ws.rs.Consumes; import javax.ws.rs.PUT; import javax.ws.rs.Path; /** * REST Web Service * * @author Administrator */ @Path("order") public class OrderResource { @PUT @Path("{order}/{food}/{table}/{price}") @Consumes("application/xml") public void putXml(@PathParam( "order" ) String order, @PathParam( "food" ) String food, @PathParam( "table" ) String table, @PathParam( "price" ) String price) { Connection connection = null; PreparedStatement InsertOrder = null; PreparedStatement InsertTable = null; PreparedStatement InsertFood = null; PreparedStatement lookupUser = null; try { Class.forName("com.mysql.jdbc.Driver"); connection = DriverManager.getConnection(Settings.DATABASE_URL, Settings.DATABASE_USER, Settings.DATABASE_PASS); String Username = order.substring(0, order.indexOf('-')); order = order.substring(order.indexOf('-') + 1); String BranchID = order.substring(0, order.indexOf('-')); order = order.substring(order.indexOf('-') + 1); String date = order.substring(0, order.indexOf('-')); date = Settings.replace(date,"_", "/"); order = order.substring(order.indexOf('-') + 1); String time = order; time = Settings.replace(time,"_", ":"); lookupUser = connection.prepareStatement( "SELECT ID FROM user WHERE Username = '" + Username + "'"); ResultSet resultSetUser = lookupUser.executeQuery(); resultSetUser.next(); String UserID = resultSetUser.getObject("ID").toString(); InsertOrder = connection.prepareStatement("insert into tbl_order (UserID,BranchID,Date,Time,Price)" + " values (" + UserID + "," + BranchID + ",'" + date + "','" + time +"'," + price + ")"); InsertOrder.executeUpdate(); InsertOrder = connection.prepareStatement("select max(ID) AS ID from tbl_order"); ResultSet resultSetOrder = InsertOrder.executeQuery(); resultSetOrder.next(); int OrederID = Integer.parseInt(resultSetOrder.getObject("ID").toString()); if(!table.equals("-")) { String tableID = table; InsertTable = connection.prepareStatement("insert into ordertable (OrderID,TableID)" + " values (" + OrederID + "," + tableID + ")"); InsertTable.executeUpdate(); } String FoodRow; if(!food.equals("-")) { while(!food.equals("")) { if(food.substring(1).indexOf('_') != -1) FoodRow = food.substring(1,food.substring(1).indexOf('_')+1); else FoodRow = food.substring(1); if(food.substring(1).indexOf('_') != -1) food = food.substring(food.substring(1).indexOf('_')+1); else food = ""; String FoodID = FoodRow.substring(0,FoodRow.indexOf('-')); FoodRow = FoodRow.substring(FoodRow.indexOf('-') + 1); String FoodNum = FoodRow; InsertFood = connection.prepareStatement("insert into orderfood (OrderID,FoodID,FoodNum)" + " values (" + OrederID + "," + FoodID + "," + FoodNum + ")"); InsertFood.executeUpdate(); } } } catch(SQLException e) { e.printStackTrace(); } catch (ClassNotFoundException cE) { System.out.println("Class Not Found Exception: "+ cE.toString()); } catch(Exception e) { e.printStackTrace(); } finally { try { InsertOrder.close(); InsertTable.close(); InsertFood.close(); lookupUser.close(); connection.close(); } catch(Exception e) { e.printStackTrace(); } } } }