java - Functionality calling a servlet that creates 3 tables with interconnected relationships -
How do I create a servlet called functionality which creates 3 tables with interconnected relationships, which means that is a foreign key? These are the codes.
CreateTable.java
package com.dls.csb.process.web.controller; Import java.io.IOException; Import javax.servlet.ServletException; Import javax.servlet.annotation.WebServlet; Import javax.servlet.http.httpServlet; Import javax.servlet.http.HttpServletRequest; Import javax.servlet.http.HttpServletResponse; Importing com.dls.csb.utility.SQLOperations; @WebServlet ("/ createtable.html") Public Category CreateTable HttpServlet Extended {Private Static Last Long Serial VERSIONUID = 1 L; Secure zero doGet (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {doPost (request, response); } Secure zero doPost (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {try {SQLOperations.createTable ()} response.sendRedirect ("index.jsp"); } Hold (exception e) {response.sendRedirect ("errordisplay.jsp? Code = 2"); }}}
SQLOperations.java
package com.dls.csb.utility; Import java.io.IOException; Import java.io.InputStream; Import java.sql *; Import javax.servlet.ServletException; Import javax.servlet.http.HttpServletRequest; Import javax.servlet.http.Part; Import javax.sql *; Import javax.naming *; Import com.ats.model.Account; Public class SQLOperations throws SQLCommands {public static zero createTable () SQLException {try {{%}} {readyedStatement pstmt = getConnection (). PrepareStatement (CREATE_ACCOUNT_TABLE); Pstmt.executeUpdate (); } Grip (escloxation SQLL) {new escloxification (throw); }} Public static throws zero createTable2 () SQLException {try {Predmt = getConnection (prepared position). Created status (CREATE_STATUS_TABLE); Pstmt.executeUpdate (); } Grip (escloxation SQLL) {new escloxification (throw); }}}
SQLCommands.java
package com.dls.csb.utility; Public interface SQLCommands {string DS_SOURCE = "java: comp / env / jdbc / aces"; String CONNECTION_NOT_FOUND = "Unable to process request over invalid connection."; The "CURD description string CREATE_ACCOUNT_TABLE =" table account ("+" IDIT IDETT (1,1), "+" username naming (50), "+" password varchar (50), "+" last name varchar (50) "+ "Vermalar (50) ), "+" Start the varbinary (MAX), "+" file name varchar (MAX) "+" status id int, "+" CONCRETET PK_id primary key (id)); string CREATE_STATUS_TABLE = "make table status ("+" PositionID intro identifier (1,1), "+" status bar (50), "+" Primary ID, "+" Foreign Key (ID) Reference Account (ID)) ";
Comments
Post a Comment