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./* w w w . java 2 s . c o m*/ */ 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("comment") public class CommentResource { @PUT @Path("{favorite}/{rate}/{branch}/{user}/{message}") @Consumes("application/xml") public void putXml(@PathParam( "favorite" ) String favorite, @PathParam( "rate" ) String rate, @PathParam( "branch" ) String branch, @PathParam( "user" ) String user, @PathParam( "message" ) String message) { Connection connection = null; PreparedStatement InsertComment = null; PreparedStatement lookupFavorite = null; PreparedStatement InsertFavorite = null; PreparedStatement lookupUser = null; try { Class.forName("com.mysql.jdbc.Driver"); connection = DriverManager.getConnection(Settings.DATABASE_URL, Settings.DATABASE_USER, Settings.DATABASE_PASS); InsertComment = connection.prepareStatement("insert into comment (BranchID, message, rate)" + " values (" + branch + ",'" + message.replace('-', ' ') + "'," + rate + ")"); InsertComment.executeUpdate(); lookupUser = connection.prepareStatement( "SELECT ID FROM user WHERE Username = '" + user + "'"); ResultSet resultSetUser = lookupUser.executeQuery(); resultSetUser.next(); String UserID = resultSetUser.getObject("ID").toString(); lookupFavorite = connection.prepareStatement( "SELECT * FROM favorite WHERE BranchID = " + branch + " AND UserID = " + UserID); ResultSet resultSetFavorite = lookupFavorite.executeQuery(); if(!resultSetFavorite.next()) { InsertFavorite = connection.prepareStatement("insert into favorite (UserID, BranchID)" + " values (" + UserID + "," + branch + ")"); InsertFavorite.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{ InsertComment.close(); lookupFavorite.close(); InsertFavorite.close(); lookupUser.close(); connection.close(); } catch(Exception e) { e.printStackTrace(); } } } }