package gunman; import javax.servlet.*; import javax.servlet.http.*; import java.io.*; import java.sql.*; public class HsqldbServlet extends HttpServlet{ public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doGet(request, response); } public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PrintWriter out = response.getWriter(); out.println("
");

		try {
			Class.forName("org.hsqldb.jdbcDriver");

//			createUser();
//			createTable();
//			grantTable();
//			insertTable();
			selectAll(out);

		} catch (Exception ex) {
//			out.println(ex.toString());
			ex.printStackTrace(out);

		}

		out.println("
"); return; } public static Connection getConnection(String user, String pwd) throws Exception { Connection con = DriverManager.getConnection( "jdbc:hsqldb:/members/0LCnZYXmjfL9fUCkwiM3xUI3cEDU355h/GUNCHARA" ,user, pwd); return con; } public static void createUser() throws Exception { Connection con = getConnection("sa", ""); //System Administrator Statement st = con.createStatement(); st.execute("CREATE USER RYUBA PASSWORD \"\""); } public static void createTable() throws Exception { Connection con = getConnection("sa", ""); Statement st = con.createStatement(); st.execute("CREATE TABLE GUNCHARA (" + "ID INTEGER NOT NULL PRIMARY KEY," + "NAME VARCHAR NOT NULL ," + "LINENUM INTEGER NOT NULL ," + "LINE1 VARCHAR NOT NULL ," + "LINE2 VARCHAR NOT NULL ," + "LINE3 VARCHAR NOT NULL ," + "LINE4 VARCHAR NOT NULL ," + "LINE5 VARCHAR NOT NULL ," + "LINE6 VARCHAR NOT NULL ," + "LINE7 VARCHAR NOT NULL " + ");" ); } public static void grantTable() throws Exception { Connection con = getConnection("sa", ""); Statement st = con.createStatement(); st.execute("GRANT ALL ON GUNCHARA TO RYUBA"); } public static void insertTable() throws Exception { Connection con = getConnection("ryuba", ""); Statement st = con.createStatement(); st.execute("INSERT INTO GUNCHARA " + "VALUES(101, 'ガンマン(正面)', 5" + " , ' __ '" + " , ' _|__|_ '" + " , ' b (@@) '" + " , ' V|~~|> '" + " , ' //T| '" + " , ' '" + " , ' '" + " )" ); st.execute("INSERT INTO GUNCHARA " + "VALUES(102, 'ガンマン(左)', 5" + " , ' __ '" + " , ' _|__|_ '" + " , ' <6 ) '" + " , ' /|~S| '" + " , ' //T| '" + " , ' '" + " , ' '" + " )" ); st.execute("INSERT INTO GUNCHARA " + "VALUES(103, 'ガンマン(右)', 5" + " , ' __ '" + " , ' _|__|_ '" + " , ' ( 6> '" + " , ' /|~~|V '" + " , ' //T| '" + " , ' '" + " , ' '" + " )" ); st.execute("INSERT INTO GUNCHARA " + "VALUES(201, '馬(左)', 4" + " , ' __AA '" + " , ' | 6 |__P '" + " , ' ~~| l '" + " , ' /_/~l_l '" + " , ' '" + " , ' '" + " , ' '" + " )" ); st.execute("INSERT INTO GUNCHARA " + "VALUES(202, '馬(右)', 4" + " , ' AA__ '" + " , ' q__| 6 | '" + " , ' | _ |~~ '" + " , ' |_||_| '" + " , ' '" + " , ' '" + " , ' '" + " )" ); st.execute("INSERT INTO GUNCHARA " + "VALUES(203, '馬(泣き)', 4" + " , ' 7_7 '" + " , ' />