Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <%@ page language="java" contentType="text/html; charset=UTF-8"
- pageEncoding="UTF-8"%>
- <%@page import="java.sql.*"%>
- <%@page import="org.json.simple.*"%>
- <%@page import="java.util.ArrayList"%>
- <%!String host = "jdbc:mysql://localhost:3306/~~~DB이름?useUnicode = true&characterEncoding=utf8";
- String server_user = "~~";
- String pw = "~~";
- Connection conn;
- PreparedStatement pstmt;
- String result;
- %>
- <%!
- public int searchGcmKey(int userNo){
- String sql = "select * from Gcm where User_No ="+userNo;
- try {
- pstmt = conn.prepareStatement(sql);
- ResultSet rs = pstmt.executeQuery(sql);
- if(rs.next()){
- rs.next();
- return -1; //값이 있다면 수정
- }else{
- return 1; // 값이 없다면 추가
- }
- } catch (Exception e) {
- return 0;//예외
- }
- }
- public void updateGcmKey(int userNo, String gcmKey) {
- String sql = "update Gcm set Gcm_Key ='"+gcmKey+"'where User_No="+userNo;
- try {
- pstmt = conn.prepareStatement(sql);
- pstmt.executeUpdate();
- pstmt.close();
- } catch (Exception e) {
- //out.println("comment write error " + e.toString());
- }
- }
- public void setGcmKey(int userNo,String gcmKey){
- try{
- Class.forName("com.mysql.jdbc.Driver");
- Connection conn = DriverManager.getConnection(host,server_user,pw);
- String sql = "insert into Gcm(User_No,Gcm_Key) values(?,?)";
- PreparedStatement pstmt = conn.prepareStatement(sql);
- pstmt.setInt(1, userNo);
- pstmt.setString(2, gcmKey);
- pstmt.executeUpdate();
- pstmt.close();
- }catch(Exception e){
- result = e.getMessage();
- }
- }
- %>
- <%
- request.setCharacterEncoding("utf-8");
- int userNo = Integer.parseInt(request.getParameter("userNo"));
- String gcmkey = request.getParameter("gcmKey");
- int search;
- try {
- Class.forName("com.mysql.jdbc.Driver");
- conn = DriverManager.getConnection(host, server_user, pw);
- } catch (Exception e) {
- out.println(e.getMessage());
- }
- search =searchGcmKey(userNo);
- if(search ==1)
- setGcmKey(userNo,gcmkey);
- else
- updateGcmKey(userNo,gcmkey);
- %>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement