List of usage examples for com.google.gson.stream JsonWriter value
public JsonWriter value(Number value) throws IOException
From source file:logInAuthentication.java
void sendRequestToDataBase(HttpServletRequest request, HttpServletResponse response) throws IOException { PrintWriter pw = response.getWriter(); response.setContentType("text/json;charset=UTF-8"); try {//from w w w .j a v a 2s . c o m Class.forName("com.mysql.jdbc.Driver"); Connection con = DriverManager.getConnection("jdbc:mysql://localhost/uhms", "root", ""); java.sql.Statement st = con.createStatement(); StaticData.phone = request.getParameter("phone"); StaticData.password = request.getParameter("password"); ResultSet rs = st .executeQuery("SELECT gardian_password from gardian_info where id=" + StaticData.phone); if (rs.next()) { String pss = rs.getString(1); if (!StaticData.password.equals(pss)) { throw new Exception("Password did not match"); } } else throw new Exception("No User Found by this Phone No"); rs = st.executeQuery("SELECT *from student_info a,gardian_info b,student_gardian_relation c" + " WHERE a.id=c.student_id AND b.id = c.gardian_id" + " AND b.id=" + StaticData.phone); StaticData.resultSet = rs; if (!rs.next()) throw new Exception("User Not Found On DATABASE"); JsonWriter gsonWriter = new JsonWriter(pw); ResultSetMetaData metaData = rs.getMetaData(); gsonWriter.beginObject(); gsonWriter.name("info"); gsonWriter.beginArray(); rs.previous(); while (rs.next()) { gsonWriter.beginObject(); for (int indx = 1; indx <= metaData.getColumnCount(); indx++) { gsonWriter.name(metaData.getColumnLabel(indx)); gsonWriter.value(rs.getString(indx)); } gsonWriter.endObject(); } gsonWriter.endArray(); gsonWriter.name("status"); gsonWriter.value("200"); gsonWriter.endObject(); gsonWriter.flush(); gsonWriter.close(); } catch (Exception ex) { JsonWriter gsonWriter = new JsonWriter(pw); gsonWriter.beginObject(); gsonWriter.name("status"); gsonWriter.value("400"); gsonWriter.name("error_desc"); gsonWriter.value(ex.getMessage()); gsonWriter.endObject(); gsonWriter.flush(); gsonWriter.close(); // pw.println(ex); } }
From source file:ToStringSerializedTypeAdapter.java
License:Apache License
@Override public void write(JsonWriter out, T value) throws IOException { if (value == null) { out.nullValue();//from ww w.j a v a 2s . c om } else { out.value(value.toString()); } }
From source file:LongDateTypeAdapter.java
License:Apache License
@Override public void write(JsonWriter out, Date value) throws IOException { if (value == null) { out.nullValue();//from w w w. ja va 2 s .c o m } else { out.value(String.valueOf(value.getTime())); } }
From source file:InstantTypeAdapter.java
License:Apache License
@Override public void write(JsonWriter out, Instant value) throws IOException { if (value == null) { out.nullValue();/*w ww. j av a2s. c om*/ } else { out.value(value.toString()); } }
From source file:CheckHallStatus.java
void sendRequestToDataBase(HttpServletRequest request, HttpServletResponse response) throws IOException { PrintWriter pw = response.getWriter(); response.setContentType("text/json;charset=UTF-8"); try {/*from w w w. j a v a 2 s . com*/ Class.forName("com.mysql.jdbc.Driver"); Connection con = DriverManager.getConnection("jdbc:mysql://localhost/uhms", "root", ""); java.sql.Statement st = con.createStatement(); StaticData.phone = request.getParameter("phone"); StaticData.password = request.getParameter("password"); StaticData.id = request.getParameter("id"); ResultSet rs = st .executeQuery("SELECT gardian_password from gardian_info where id=" + StaticData.phone); if (rs.next()) { String pss = rs.getString(1); if (!StaticData.password.equals(pss)) { throw new Exception("Password did not match"); } } else { throw new Exception("No User Found by this Phone No"); } rs = st.executeQuery( "SELECT gardian_id FROM student_gardian_relation where student_id=" + StaticData.id); if (rs.next()) { String id = rs.getString(1); if (!StaticData.phone.contains(id)) { throw new Exception("Gardian And Student Info Not related"); } } else { throw new Exception("Unauthorized Access"); } rs = st.executeQuery( "SELECT * from check_in_out where day_time = (select MAX(day_time) from check_in_out WHERE id =" + StaticData.id + ")"); JsonWriter gsonWriter = new JsonWriter(pw); ResultSetMetaData metaData = rs.getMetaData(); if (rs.next()) { gsonWriter.beginObject(); for (int i = 0; i < metaData.getColumnCount(); i++) { gsonWriter.name(metaData.getColumnLabel(i + 1)); gsonWriter.value(rs.getString(i + 1)); } } else { throw new Exception("Student information Not Found"); } //currret month meal calculation Calendar calendar = Calendar.getInstance(); System.out.println(calendar); Timestamp current = new Timestamp(calendar.getTimeInMillis()); // System.out.println(current); calendar.set(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), 1, 0, 0, 0); Timestamp start = new Timestamp(calendar.getTimeInMillis()); calendar.set(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.getMaximum(Calendar.DAY_OF_MONTH), 23, 59, 59); Timestamp end = new Timestamp(calendar.getTimeInMillis()); rs = st.executeQuery("select sum(quantity) from meal_log where id=" + StaticData.id + " AND day_time>= '" + start + "' AND day_time<='" + end + "' AND type='BREAKFAST'"); gsonWriter.name("BREAKFAST"); if (rs.next()) { gsonWriter.value(rs.getInt(1) + ""); } else { gsonWriter.value("0"); } rs = st.executeQuery("select sum(quantity) from meal_log where id=" + StaticData.id + " AND day_time>= '" + start + "' AND day_time<='" + end + "' AND type='LUNCH'"); gsonWriter.name("LUNCH"); if (rs.next()) { gsonWriter.value(rs.getInt(1) + ""); } else { gsonWriter.value("0"); } rs = st.executeQuery("select sum(quantity) from meal_log where id=" + StaticData.id + " AND day_time>= '" + start + "' AND day_time<='" + end + "' AND type='DINNER'"); gsonWriter.name("DINNER"); if (rs.next()) { gsonWriter.value(rs.getInt(1) + ""); } else { gsonWriter.value("0"); } //calculate meal rate rs = st.executeQuery("select sum(quantity) from meal_log where day_time>= '" + start + "' AND day_time<='" + end + "'"); rs.next(); int totalMeal = rs.getInt(1); rs = st.executeQuery("select sum(amount) from bazar_info where day_time>= '" + start + "' AND day_time<='" + end + "'"); rs.next(); int totalBazarAmount = rs.getInt(1); gsonWriter.name("meal_rate"); gsonWriter.value((double) totalBazarAmount / totalMeal + ""); gsonWriter.name("status"); gsonWriter.value("200"); gsonWriter.endObject(); gsonWriter.flush(); gsonWriter.close(); } catch (Exception ex) { JsonWriter gsonWriter = new JsonWriter(pw); gsonWriter.beginObject(); gsonWriter.name("status"); gsonWriter.value("400"); gsonWriter.name("error_desc"); gsonWriter.value(ex.getMessage()); gsonWriter.endObject(); gsonWriter.flush(); gsonWriter.close(); // pw.println(ex); } }
From source file:ChangePassword.java
void sendRequestToDataBase(HttpServletRequest request, HttpServletResponse response) throws IOException { PrintWriter pw = response.getWriter(); response.setContentType("text/json;charset=UTF-8"); try {//from w w w. j a v a 2 s. c o m Class.forName("com.mysql.jdbc.Driver"); Connection con = DriverManager.getConnection("jdbc:mysql://localhost/uhms", "root", ""); java.sql.Statement st = con.createStatement(); StaticData.phone = request.getParameter("phone"); StaticData.password = request.getParameter("oldpassword"); StaticData.newPassword = request.getParameter("newpassword"); ResultSet rs = st .executeQuery("SELECT gardian_password from gardian_info where id=" + StaticData.phone); if (rs.next()) { String pss = rs.getString(1); if (!StaticData.password.equals(pss)) { throw new Exception("Enter Current Password Correctly."); } } else throw new Exception("No User Found by this Phone No"); if (StaticData.newPassword.isEmpty()) throw new Exception("Password can't be empty."); int executeUpdate = st.executeUpdate("UPDATE gardian_info SET gardian_password = '" + StaticData.newPassword + "'" + " WHERE id=" + StaticData.phone); JsonWriter gsonWriter = new JsonWriter(pw); gsonWriter.beginObject(); if (executeUpdate != 1) throw new Exception("Password Change failed."); gsonWriter.name("status"); gsonWriter.value("200"); gsonWriter.name("message"); gsonWriter.value("Password Changed Successfully."); gsonWriter.endObject(); gsonWriter.flush(); gsonWriter.close(); } catch (Exception ex) { JsonWriter gsonWriter = new JsonWriter(pw); gsonWriter.beginObject(); gsonWriter.name("status"); gsonWriter.value("400"); gsonWriter.name("error_desc"); gsonWriter.value(ex.getMessage()); gsonWriter.endObject(); gsonWriter.flush(); gsonWriter.close(); // pw.println(ex); } }
From source file:DateTimeTypeAdapter.java
License:Apache License
@Override public void write(JsonWriter out, DateTime value) throws IOException { if (value == null) { out.nullValue();/*from w ww . j a v a 2 s . co m*/ } else { out.value(value.toString()); } }
From source file:abtlibrary.utils.as24ApiClient.JSON.java
License:Apache License
@Override public void write(JsonWriter out, DateTime date) throws IOException { if (date == null) { out.nullValue();/*from w ww . j a v a 2 s . com*/ } else { out.value(formatter.print(date)); } }
From source file:abtlibrary.utils.as24ApiClient.JSON.java
License:Apache License
@Override public void write(JsonWriter out, LocalDate date) throws IOException { if (date == null) { out.nullValue();/*w ww .j a va 2 s . c o m*/ } else { out.value(formatter.print(date)); } }
From source file:at.orz.arangodb.entity.CollectionStatusTypeAdapter.java
License:Apache License
@Override public void write(JsonWriter out, CollectionStatus value) throws IOException { out.value(value.status()); }