<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1" import="java.net.*,java.sql.*"%>
<%
	Connection conn = null;
	PreparedStatement stmt = null;
	ResultSet rs = null;
	try
	{
		Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
		conn = DriverManager.getConnection("jdbc:odbc:DragDrop");

		if (request.getParameter("RequestType").equals("get"))
		{
			String sql = "SELECT DragOrder FROM DragOrders WHERE UserID=?";
			stmt = conn.prepareStatement(sql);
			stmt.setString(1, request.getParameter("UserID"));
			
			rs = stmt.executeQuery();
			rs.next();
			out.write(rs.getString("DragOrder"));
		}
		else if (request.getParameter("RequestType").equals("set"))
		{
			String dragOrder = URLDecoder.decode(request.getParameter("strJSON"),"UTF-8");
			String sql = "UPDATE DragOrders SET DragOrder=? WHERE UserID=?";
			stmt = conn.prepareStatement(sql);
			stmt.setString(1, dragOrder);
			stmt.setString(2, request.getParameter("UserID"));
			stmt.executeUpdate();
		}
	}
	catch (Exception e)
	{
		out.write("failed: " + e.toString());
	}
	finally 
	{
		if (rs != null) rs.close();
		if (stmt != null) stmt.close();
		if (conn != null) conn.close();
	}
%>