// Finish by processing our deletes
<%@ page import="java.sql.*" %>
<%@ page import="eba.gethandler.Record" %>
<%@ page import="eba.savehandler.SaveHandler" %>
<%
/** *******************************
This file is used as a Save Handler for the Grid control. When the user clicks
the save button in index.jsp a datagram is sent to this script.
The script in turn looks at each update in the datagram and processes them accordingly.
We have provided all the necessary functionality in the SaveHandler class to extract any of the update instructions.
For more details please have a look at our shipped online help under Reference/Server
*********************************** */
/** *******************************
Figure out the path to the mdb file that has the needed data
We need to create:
C:\Program Files\eBusiness Applications\Combo 3.X\Jsp Trial\samples\Basic\Filter\data\customerdb.mdb
This breaks down to the following:
[C:\Program Files\eBusiness Applications\Combo 3.X\Jsp Trial\]+[samples\Basic\Filter]+[\data\customerdb.mdb]
The above breakdown maps to the following:
getRealPath("') ---> [C:\Program Files\eBusiness Applications\Combo 3.X\Jsp Trial\]
getServletPath() ---> [samples\Basic\Filter] (get.jsp is removed)
hard code string ---> [\data\customerdb.mdb]
*/
// from the URL we need to remove the first three tokens [http:/][/localhost:8080][/v32betaJSPSamples/]
// Token 4 to N need to be added to the value returned from getRealPath
// Also the last token is the name of the get handler
String pathAfterContext = request.getServletPath();
// remove the get.jsp part.
pathAfterContext = pathAfterContext.substring(0,pathAfterContext.lastIndexOf("')).replace('/','\\');
// get the complete path on the server of our database.
String path = config.getServletContext().getRealPath("') + pathAfterContext + "\\data\\NorthWindUltra.mdb";
// get the database connection
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
Connection con=DriverManager.getConnection("jdbc:odbc:Driver={MicroSoft Access Driver (*.mdb)};DBQ=" + path,"","");
// get the ResultSet of the table tblPricing in our database
Statement st=con.createStatement();
// Instanciate the eBusiness Applications' class 'SaveHandler'. This class is defined in ebaxmlconverter.jar
SaveHandler mySaveHandler=new SaveHandler(request,out);
// Begin by processing the inserts
Record[] insertRecords = mySaveHandler.getInsertRecords();
for (int i=0; i< insertRecords.length; i++) {
String sql= "tblCustomers (CustomerName, ContactName, ContactEmail, ContactTitle, PhoneNumber, Address, Country) VALUES (" ;
sql+= "'" + insertRecords[i].getField("CustomerName") + "',";
sql+= "'" + insertRecords[i].getField("ContactName") + "',";
sql+= "'" + insertRecords[i].getField("ContactEmail") + "',";
sql+= "'" + insertRecords[i].getField("ContactTitle") + "',";
sql+= "'" + insertRecords[i].getField("PhoneNumber") + "',";
sql+= "'" + insertRecords[i].getField("Address") + "',";
sql+= "'" + insertRecords[i].getField("Country") + "'";
sql+= "); ";
st.executeUpdate(sql);
}
// Continue by processing our updates
Record[] updateRecords = mySaveHandler.getUpdateRecords();
for (int i=0; i< updateRecords.length; i++) {
String sql = "UPDATE tblCustomers ";
sql+= "SET ";
sql+= "Address = '" + updateRecords[i].getField("Address") + "' ";
sql+=" WHERE CustomerID = " + updateRecords[i].getID() + "";
st.executeUpdate(sql);
}
// Finish by processing our deletes
Record[] deleteRecords = mySaveHandler.getDeleteRecords();
for (int i=0; i< deleteRecords.length; i++) {
String sql = "DELETE FROM tblCustomers WHERE CustomerID = '" + deleteRecords[i].getID() + "'";
st.executeUpdate(sql);
}
st.close();
con.close();
// reports back to the Grid that the update has successfully been completed
mySaveHandler.writeToClient();
%>