Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 476
  • Last Modified:

JSP / FORM / DB2

I have had great help here on expert exchange and thought I had solved my issue and learning, but was asked instead of a servlet to have a form.jsp with the fields so the user can check them before the information is submitted to the database. I am not really good at code so some pointers help would be great. Here is the servlet I have right now.

package com.arkona;

import java.io.IOException;
import java.sql.Connection;
// import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
// import java.sql.SQLException;

import javax.servlet.Servlet;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class Simple extends HttpServlet implements Servlet {
      /*
       * (non-Java-doc)
       *
       * @see javax.servlet.http.HttpServlet#HttpServlet()
       */
      public Simple() {
            super();
      }
      
      /*
       * (non-Java-doc)
       *
       * @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest arg0,
       *      HttpServletResponse arg1)
       */
      protected void doGet(HttpServletRequest rq, HttpServletResponse rs) throws ServletException, IOException {
            
            
            
            try{
                  
                  Class.forName("com.ibm.db2.jcc.DB2Driver").newInstance();
                Connection conn = DriverManager.getConnection("jdbc:db2://arkona-db2-dev.arkona.com:50001/ARKDLS","username", "password");
                  PreparedStatement ps = conn.prepareStatement("insert into DB2INST1.DLDATA(COMPANYID, LICENSE, FIRSTNAME, LASTNAME, ADDRESS, CITY, STATE) values (?,?,?,?,?,?,?)");
                  ps.setString(1,rq.getParameter("CompanyID"));
                  ps.setString(2,rq.getParameter("License"));
                  ps.setString(3,rq.getParameter("FirstName"));
                  ps.setString(4,rq.getParameter("LastName"));
                  ps.setString(5,rq.getParameter("Address"));
                  ps.setString(6,rq.getParameter("City"));
                  ps.setString(7,rq.getParameter("State"));
                  ps.executeUpdate();
                  ps.close();
                  
                  // conn.commit();
            }
            catch(Exception e)
            {
             e.printStackTrace();
            }
      }
      /*
       * (non-Java-doc)
       *
       * @see javax.servlet.http.HttpServlet#doPost(HttpServletRequest arg0,
       *      HttpServletResponse arg1)
       */
      protected void doPost(HttpServletRequest arg0, HttpServletResponse arg1)
      throws ServletException, IOException {
            // TODO Auto-generated method stub
      }
      
}


So as you can tell I have that working so any help how do this in a form.jsp would be great
0
jareddraper
Asked:
jareddraper
  • 28
  • 17
1 Solution
 
KuldeepchaturvediCommented:
:-) I just replied to your previous question on the same...
0
 
jareddraperAuthor Commented:
ok I understand your answer to a point and I have seen a bit of example code. So would I turn the existing servlet code into a java bean then call it with jsp tags. I am using IBM rational developer  to do this. The servlet made sense to me but the jsp structure doesn't. Sorry for what seem very novice dumb questions.
0
 
KuldeepchaturvediCommented:
(If I am understanding the requirement correctly)..
I suggest that you keep the servlet to do the database insert.. create a separate jsp which has the form where user enters the data and submits the page to the servlet...

if you STILL are receiving the data from your external application than this design will change a little.... tell me exactly what your jsp is suppose to do and then we can start designing it.
0
Transaction-level recovery for Oracle database

Veeam Explore for Oracle delivers low RTOs and RPOs with agentless transaction log backup and transaction-level recovery of Oracle databases. You can restore the database to a precise point in time, even to a specific transaction.

 
jareddraperAuthor Commented:
I will still get the string of data via the url from the application

again it comes from the app to me like this

http://some.localhost.com/form.jsp?License%3D5555555&FirstName%3DTest&LastName%3DUser&State%3DAZ

I still haven't figured out why it encodes the = sign with %3D and even with my servlet I was running into that issue.

I would like to take that information and prepopulate a jsp form with the information that the end user will see and make changes if the information is incorrect. Once the correct information is verified by the user the hit submit which send the info to the database.
0
 
KuldeepchaturvediCommented:
Okay that should be a fairly simple jsp...

we will still keep the servlet to do the actual insert to the database..

simple logic will be:

1. Recieve the data from URL to jsp ( using request.getParameter()).
2 .Put them in a HTML form...
3. Let user change them if they need to..
4. Submit the page to the servlet to do the actual insert..

I am not sure how much of a jsp knowledge you have... Lets start by making a Simple HTML form and then I will help you to convert it to jsp...

I can give you a pre-written jsp.. but then you wont learn jsp that way...:-)
I would rather teach you how to fish.. then giving you a fish....:-)
0
 
jareddraperAuthor Commented:
I would rather learn as well. I don't know very much and the tools I am using being IBM Rational Web which is eclipse with all the IBM plugins it has drag and drop things but I would rather learn the code ans it makes more sense then the gui stuff. If you could just get me started on the code with like one of the how to get the first parameter let me go from there until I either break it :) or get it working that would be great something very simple just to show the concept then I can try and see how far I can get. again I really thank  you for taking all this time to help me
0
 
KuldeepchaturvediCommented:
Lets start with this simple tutorial..
http://www.caucho.com/resin-3.0/jsp/tutorial/
go thru this and try to write the jsp that we need for our purposes...

then we will take it from there
0
 
jareddraperAuthor Commented:
ok great I will get to work on this and let you know how it goes.
0
 
jareddraperAuthor Commented:
ok so I got a simple html form and jsp page returning results now. Here is the simple code

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<form action="form.jsp" method="get" enctype="application/x-www-form-urlencoded">

<table>
      <tr><td><b>Name</b>
      <td><input type="text" name="name">
      
<tr><td><b>Favorite Color</b>
      <td><input type="text" name="color">
</table>

<input type="submit" value="send"></form>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

Name <%= request.getParameter("name") %> <br>
Color <% request.getParameter("color"); %>

my question is on the form how do I get the information from a url like this

http://localhost:9080/learn/servlet/simple?CompanyID%3DAR1&License%3D12345643&FirstName%3DRobert&LastName%3DBreault&Address%3D10747%20South%20Redwood%20Road&City%3DSouth%20Jordan&State%3DUT


again I unsure why the application encodes the = with %3D and can't seem to find a way to change that. So if you could give a simple example how to grab that to populate my form I will continue from there to try and get to the next step.

Thanks,
0
 
jareddraperAuthor Commented:
ok I am trying something like this in my form.jsp but it gives an error like this when ran

CompanyID: <input type="text" name='<% request.getParameter("CompanyID") %>'>

Error output

JSP Processing Error
HTTP Error Code:   500

Error Message:

JSPG0049E: /form.jsp failed to compile :
JSPG0091E: An error occurred at line: 5 in the file: /form.jsp
JSPG0093E: Generated servlet error from file: /form.jsp
/opt/IBM/WebSphere/AppServer1/profiles/default/temp/rbreault-t60Node01/server1/learnEAR/learn.war/_form.java:67: ';' expected
      request.getParameter("CompanyID")
                                       ^
1 error

Root Cause:

com.ibm.ws.jsp.JspCoreException: JSPG0049E: /form.jsp failed to compile :
JSPG0091E: An error occurred at line: 5 in the file: /form.jsp
JSPG0093E: Generated servlet error from file: /form.jsp
/opt/IBM/WebSphere/AppServer1/profiles/default/temp/rbreault-t60Node01/server1/learnEAR/learn.war/_form.java:67: ';' expected
      request.getParameter("CompanyID")
                                       ^
1 error
      at com.ibm.ws.jsp.webcontainerext.JSPExtensionServletWrapper.translateJsp(JSPExtensionServletWrapper.java:306)
      at com.ibm.ws.jsp.webcontainerext.JSPExtensionServletWrapper.checkForTranslation(JSPExtensionServletWrapper.java:265)
      at com.ibm.ws.jsp.webcontainerext.JSPExtensionServletWrapper.handleRequest(JSPExtensionServletWrapper.java:137)
      at com.ibm.ws.jsp.webcontainerext.JSPExtensionProcessor.handleRequest(JSPExtensionProcessor.java:230)
      at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:2837)
      at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:220)
      at com.ibm.ws.webcontainer.VirtualHost.handleRequest(VirtualHost.java:204)
      at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:1681)
      at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:77)
      at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:421)
      at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewInformation(HttpInboundLink.java:367)
      at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.ready(HttpInboundLink.java:276)
      at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.sendToDiscriminaters(NewConnectionInitialReadCallback.java:201)
      at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.complete(NewConnectionInitialReadCallback.java:103)
      at com.ibm.ws.tcp.channel.impl.WorkQueueManager.requestComplete(WorkQueueManager.java:548)
      at com.ibm.ws.tcp.channel.impl.WorkQueueManager.attemptIO(WorkQueueManager.java:601)
      at com.ibm.ws.tcp.channel.impl.WorkQueueManager.workerRun(WorkQueueManager.java:934)
      at com.ibm.ws.tcp.channel.impl.WorkQueueManager$Worker.run(WorkQueueManager.java:1021)
      at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java(Compiled Code))

I was trying to get info from the URL and add it to the fields but let the end user edit the information if it is incorrect before they submit it. Also I am having issues with that stupid encoding the application does
0
 
jareddraperAuthor Commented:
nevermind the top part of the last entry I was missing the = sign :P

CompanyID: <input type="text" name='<%= request.getParameter("CompanyID") %>'> <br>

But again the encoding any help would be great with that as I think I am getting closer but moving slowly :)
0
 
jareddraperAuthor Commented:
nevermind that still didn't work it didn't bring in the value I didn't get any error but it didn't enter the CompanyID information ?
0
 
KuldeepchaturvediCommented:
<input type="text" name='<% request.getParameter("CompanyID") %>'>

should have been

<input type="text" value='<% request.getParameter("CompanyID") %>' Name="CompnyID">

& similar for all other input fields.
0
 
jareddraperAuthor Commented:
ok I will give that a try. Any idea on the encoding issue if I change the url by hand and change %3D to = its works but the application doesn't let me change how it encodes the url. How can I unencode that url to get the values because with the encoding I get null values.
0
 
KuldeepchaturvediCommented:
well if you can not change the  application then you have a messy way to handle it..

logic is:
First use method:

request.getQueryString();

It will return you everything that is there after the "?" in the URL..

then you take the string and substring it at every &..  then for every substring you break it again on %3D...
first part is the parameter name and second part in the parameter value.
0
 
jareddraperAuthor Commented:
That line of code did return what I was looking for. Thank again just need the encoding issue and the submit for the database after user verifies data. Slowly starting to get this thank you for all your help with this.
0
 
jareddraperAuthor Commented:
ok part is finished found a setting in app to set = to = instead of %3D

Now I need help with the submit button so it sends to the database and help with the following code it does what I want but its a paragraph style instead of table and I don't know how to change what I have.

<td class="COPY" align="left" valign="top">
                                                                                          <table class="COPY" border="0" cellpadding="10"
                                                                                                cellspacing="0" width="100%">
                                                                                                <tbody>
                                                                                                      <tr>
                                                                                                            <td>
                                                                                                            <p class="h3"></p>
                                                                                                            <P>Company ID: <input type="text"
                                                                                                                  value='<%= request.getParameter("CompanyID") %>'
                                                                                                                  Name="CompnyID"><br>
                                                                                                            License: <INPUT type="text"
                                                                                                                  value='<%= request.getParameter("License") %>'
                                                                                                                  name="License"><br>
                                                                                                            First Name: <input type="text"
                                                                                                                  value='<%= request.getParameter("FirstName") %>'
                                                                                                                  Name="FirstName"><br>
                                                                                                            Middle Name: <input type="text"
                                                                                                                  value='<%= request.getParameter("MiddleName") %>'
                                                                                                                  Name="MiddleName"><br>
                                                                                                            Last Name: <input type="text"
                                                                                                                  value='<%= request.getParameter("LastName") %>'
                                                                                                                  Name="LastName"><br>
                                                                                                            Address: <input type="text"
                                                                                                                  value='<%= request.getParameter("Address") %>'
                                                                                                                  Name="Address"><br>
                                                                                                            City: <input type="text"
                                                                                                                  value='<%= request.getParameter("City") %>'
                                                                                                                  Name="City"><br>
                                                                                                            State: <input type="text"
                                                                                                                  value='<%= request.getParameter("State") %>'
                                                                                                                  Name="State"><br>
                                                                                                            </p>
                                                                                                            <p></p>
                                                                                                            </td>
                                                                                                      </tr>
                                                                                                </tbody>
                                                                                          </table>
                                                                                          </td>
0
 
jareddraperAuthor Commented:
Ignore most of that last post I was able to figure out the table thing. I only need to the submit button now any examples would be great
0
 
KuldeepchaturvediCommented:
okay so now you should wrap your table inside a form tag.. and but a button at the bottom to submit the page..

<FORM ACTION="../servlet/yourservlet" method="POST" name="myform">
<td class="COPY" align="left" valign="top">
                                                                                          <table class="COPY" border="0" cellpadding="10"
                                                                                                cellspacing="0" width="100%">
                                                                                                <tbody>
                                                                                                      <tr>
                                                                                                            <td>
                                                                                                            <p class="h3"></p>
                                                                                                            <P>Company ID: <input type="text"
                                                                                                                  value='<%= request.getParameter("CompanyID") %>'
...
...
...
...
<INPUT TYPE="SUBMIT" VALUE="Submit" name="mybutton">
</Form>
//rest of your html
0
 
jareddraperAuthor Commented:
ok great one other question when I hit submit it will tak the new value entered if that has been changed / updated from the initial input of the data from the request.getParameter ? Correct? And the servlet I call is the original servlet I wrote correct?
0
 
KuldeepchaturvediCommented:
correct to both of your assumptions...
the servlet will keep working just like before "PROVIDED that your fields names are matching exactly to the previous names"..

there one more error that you should encounter but I want you to encounter that error before fixing it..:-)
0
 
jareddraperAuthor Commented:
ok question I added those lines and I can now click submit and activate the sevlet but it just calls it in a new window and doesn't add any info it looks like this after..

Form Url

http://localhost:9080/learn/arkona.jsp?CompanyID=AR1&License=12345&FirstName=Test&MiddleName=R&LastName=User&State=UT&City=WVC

after I hit submit I get a new window with this

http://localhost:9080/learn/simple


Here is a copy of the code I have

<td>
                                                                                                            <p class="h3" align="left"><B><FONT color="#4e75b1"><U>Arkona
                                                                                                            Drivers License Scanner</U></FONT></B></p>
                                                                                                            <FORM ACTION="/learn/simple" method="POST"
                                                                                                                  name="arkona" target="_self">
                                                                                                            <TABLE border="1">
                                                                                                                  <TBODY>
                                                                                                                        <TR>
                                                                                                                              <TD width="109">Company ID:</TD>
                                                                                                                              <TD width="160"><INPUT type="text"
                                                                                                                                    value='<%= request.getParameter("CompanyID") %>'
                                                                                                                                    name="CompnyID" size="25"></TD>
                                                                                                                        </TR>
                                                                                                                        <TR>
                                                                                                                              <TD width="109">License:</TD>
                                                                                                                              <TD width="160"><INPUT type="text"
                                                                                                                                    value='<%= request.getParameter("License") %>'
                                                                                                                                    name="License" size="25"></TD>
                                                                                                                        </TR>
                                                                                                                        <TR>
                                                                                                                              <TD width="109">First Name:</TD>
                                                                                                                              <TD width="160"><INPUT type="text"
                                                                                                                                    value='<%= request.getParameter("FirstName") %>'
                                                                                                                                    name="FirstName" size="25"></TD>
                                                                                                                        </TR>
                                                                                                                        <TR>
                                                                                                                              <TD width="109">Middle Name:</TD>
                                                                                                                              <TD width="160"><INPUT type="text"
                                                                                                                                    value='<%= request.getParameter("MiddleName") %>'
                                                                                                                                    name="MiddleName" size="25"></TD>
                                                                                                                        </TR>
                                                                                                                        <TR>
                                                                                                                              <TD width="109">Last Name:</TD>
                                                                                                                              <TD width="160"><INPUT type="text"
                                                                                                                                    value='<%= request.getParameter("LastName") %>'
                                                                                                                                    name="LastName" size="25"></TD>
                                                                                                                        </TR>
                                                                                                                        <TR>
                                                                                                                              <TD width="109">Address:</TD>
                                                                                                                              <TD width="160"><INPUT type="text"
                                                                                                                                    value='<%= request.getParameter("Address") %>'
                                                                                                                                    name="Address" size="25"></TD>
                                                                                                                        </TR>
                                                                                                                        <TR>
                                                                                                                              <TD width="109">City:</TD>
                                                                                                                              <TD width="160"><INPUT type="text"
                                                                                                                                    value='<%= request.getParameter("City") %>'
                                                                                                                                    name="City" size="25"></TD>
                                                                                                                        </TR>
                                                                                                                        <TR>
                                                                                                                              <TD width="109">State:</TD>
                                                                                                                              <TD width="160"><INPUT type="text"
                                                                                                                                    value='<%= request.getParameter("State") %>'
                                                                                                                                    name="State" size="25"></TD>
                                                                                                                        </TR>
                                                                                                                        <TR>
                                                                                                                              <TD width="109">Zip:</TD>
                                                                                                                              <TD width="160"><INPUT type="text"
                                                                                                                                    value='<%= request.getParameter("Zip") %>'
                                                                                                                                    name="Zip" size="25"></TD>
                                                                                                                        </TR>
                                                                                                                  </TBODY>
                                                                                                            </TABLE>
                                                                                                            <p><INPUT type="submit" name="Submit" value="Submit"></p>
                                                                                                            </FORM>
                                                                                                            </td>
0
 
jareddraperAuthor Commented:
Also after submit how would I close the IE / Firefox window? If that is possiable
0
 
KuldeepchaturvediCommented:
It should not be opening up a new window.....

& its not adding the record because we are calling the doPost() method and not the doGet Method of the servlet..

<FORM ACTION="/learn/simple" method="POST"
                                                                                                                  name="arkona" target="_self"> Method POST means that servlets doPOST will get executed .. ( which is empty in our servlet)..

so you have to call the doGet() in your doPOST and it should start inserting the rows..
As far as closing the browser is concerned.. it can be done by sending some HTML code back to the browser and specifying window.close() method in it...
0
 
jareddraperAuthor Commented:
"so you have to call the doGet() in your doPOST and it should start inserting the rows.."

Ok I am lost on this I tried it with a get and no differance and not sure why but it does open a new window

Here is code


<td>
                                                                                                            <p class="h3" align="left"><B><FONT color="#4e75b1"><U>Arkona
                                                                                                            Drivers License Scanner</U></FONT></B></p>
                                                                                                            <FORM ACTION="/learn/simple" method="get"
                                                                                                                  name="arkona" target="_self">
                                                                                                            <TABLE border="1">
                                                                                                                  <TBODY>
                                                                                                                        <TR>
                                                                                                                              <TD width="109">Company ID:</TD>
                                                                                                                              <TD width="160"><INPUT type="text"
                                                                                                                                    value='<%= request.getParameter("CompanyID") %>'
                                                                                                                                    name="CompnyID" size="25"></TD>
                                                                                                                        </TR>
                                                                                                                        <TR>
                                                                                                                              <TD width="109">License:</TD>
                                                                                                                              <TD width="160"><INPUT type="text"
                                                                                                                                    value='<%= request.getParameter("License") %>'
                                                                                                                                    name="License" size="25"></TD>
                                                                                                                        </TR>
                                                                                                                        <TR>
                                                                                                                              <TD width="109">First Name:</TD>
                                                                                                                              <TD width="160"><INPUT type="text"
                                                                                                                                    value='<%= request.getParameter("FirstName") %>'
                                                                                                                                    name="FirstName" size="25"></TD>
                                                                                                                        </TR>
                                                                                                                        <TR>
                                                                                                                              <TD width="109">Middle Name:</TD>
                                                                                                                              <TD width="160"><INPUT type="text"
                                                                                                                                    value='<%= request.getParameter("MiddleName") %>'
                                                                                                                                    name="MiddleName" size="25"></TD>
                                                                                                                        </TR>
                                                                                                                        <TR>
                                                                                                                              <TD width="109">Last Name:</TD>
                                                                                                                              <TD width="160"><INPUT type="text"
                                                                                                                                    value='<%= request.getParameter("LastName") %>'
                                                                                                                                    name="LastName" size="25"></TD>
                                                                                                                        </TR>
                                                                                                                        <TR>
                                                                                                                              <TD width="109">Address:</TD>
                                                                                                                              <TD width="160"><INPUT type="text"
                                                                                                                                    value='<%= request.getParameter("Address") %>'
                                                                                                                                    name="Address" size="25"></TD>
                                                                                                                        </TR>
                                                                                                                        <TR>
                                                                                                                              <TD width="109">City:</TD>
                                                                                                                              <TD width="160"><INPUT type="text"
                                                                                                                                    value='<%= request.getParameter("City") %>'
                                                                                                                                    name="City" size="25"></TD>
                                                                                                                        </TR>
                                                                                                                        <TR>
                                                                                                                              <TD width="109">State:</TD>
                                                                                                                              <TD width="160"><INPUT type="text"
                                                                                                                                    value='<%= request.getParameter("State") %>'
                                                                                                                                    name="State" size="25"></TD>
                                                                                                                        </TR>
                                                                                                                        <TR>
                                                                                                                              <TD width="109">Zip:</TD>
                                                                                                                              <TD width="160"><INPUT type="text"
                                                                                                                                    value='<%= request.getParameter("Zip") %>'
                                                                                                                                    name="Zip" size="25"></TD>
                                                                                                                        </TR>
                                                                                                                  </TBODY>
                                                                                                            </TABLE>
                                                                                                            <p><INPUT type="submit" name="Submit" value="Submit"></p>
                                                                                                             </FORM>
                                                                                                            </td>
0
 
jareddraperAuthor Commented:
ok never mind last post it was cached in my browser a restart fixed window issue. And it grabbed all the current information and rebuilt the url to send it to the servlet.

Now onto closing the browser

if I google window.close() will I find some html examples? or do you have a simple one I can follow
0
 
KuldeepchaturvediCommented:
have you tried putting some debug comments in your servlets to see that we are actually hitting it?

like a System.out.println("I am here"); types?

also take out the target from the form tag and see what it does..
0
 
KuldeepchaturvediCommented:
>
 google window.close() will I find some html examples? or do you have a simple one I can follow

Google shd give you plenty of those
0
 
jareddraperAuthor Commented:
Dang go figure I am completely lost now on this I have found examples but I am not sure where to add them to my code or anything
0
 
KuldeepchaturvediCommented:
:-)
in your servlet after you are done inserting the data, either you need to redirect to a HTML page (using response.redirect() method)..

OR you need to write out the HTML back to the browser which closes it..

both are easy and you can find 100 examples of both methods..
0
 
jareddraperAuthor Commented:
OK I will keep looking this is the way I would like to do this

write out the HTML back to the browser which closes it.

So I will search for ways to do that and let you know how it goes
0
 
jareddraperAuthor Commented:
ok wierd now when I hit submit I get this error from the servlet.

:559 MDT] 00000027 SystemErr     R com.ibm.db2.jcc.c.SqlException: DB2 SQL error: SQLCODE: -407, SQLSTATE: 23502, SQLERRMC: TBSPACEID=2, TABLEID=2, COLNO=1
      at com.ibm.db2.jcc.c.fg.d(fg.java:1340)
      at com.ibm.db2.jcc.b.gb.k(gb.java:351)
      at com.ibm.db2.jcc.b.gb.a(gb.java:60)
      at com.ibm.db2.jcc.b.w.a(w.java:52)
      at com.ibm.db2.jcc.b.wb.c(wb.java:213)
      at com.ibm.db2.jcc.c.gg.ab(gg.java:1779)
      at com.ibm.db2.jcc.c.gg.d(gg.java:2324)
      at com.ibm.db2.jcc.c.gg.W(gg.java:457)
      at com.ibm.db2.jcc.c.gg.executeUpdate(gg.java:440)
      at com.arkona.Simple.doGet(Simple.java:49)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:743)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
      at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1212)
      at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:629)
      at com.ibm.ws.webcontainer.servlet.CacheServletWrapper.handleRequest(CacheServletWrapper.java:80)
      at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:1657)
      at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:77)
      at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:421)
      at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewInformation(HttpInboundLink.java:367)
      at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.ready(HttpInboundLink.java:276)
      at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.sendToDiscriminaters(NewConnectionInitialReadCallback.java:201)
      at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.complete(NewConnectionInitialReadCallback.java:103)
      at com.ibm.ws.tcp.channel.impl.WorkQueueManager.requestComplete(WorkQueueManager.java:548)
      at com.ibm.ws.tcp.channel.impl.WorkQueueManager.attemptIO(WorkQueueManager.java:601)
      at com.ibm.ws.tcp.channel.impl.WorkQueueManager.workerRun(WorkQueueManager.java:934)
      at com.ibm.ws.tcp.channel.impl.WorkQueueManager$Worker.run(WorkQueueManager.java:1021)
      at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1332)

[4/5/07 10:21:54:559 MDT] 00000027 SystemErr     R       at com.ibm.db2.jcc.c.fg.d(fg.java:1340)
[4/5/07 10:21:54:559 MDT] 00000027 SystemErr     R       at com.ibm.db2.jcc.b.gb.k(gb.java:351)
[4/5/07 10:21:54:559 MDT] 00000027 SystemErr     R       at com.ibm.db2.jcc.b.gb.a(gb.java:60)
[4/5/07 10:21:54:559 MDT] 00000027 SystemErr     R       at com.ibm.db2.jcc.b.w.a(w.java:52)
[4/5/07 10:21:54:559 MDT] 00000027 SystemErr     R       at com.ibm.db2.jcc.b.wb.c(wb.java:213)
[4/5/07 10:21:54:559 MDT] 00000027 SystemErr     R       at com.ibm.db2.jcc.c.gg.ab(gg.java:1779)
[4/5/07 10:21:54:560 MDT] 00000027 SystemErr     R       at com.ibm.db2.jcc.c.gg.d(gg.java:2324)
[4/5/07 10:21:54:560 MDT] 00000027 SystemErr     R       at com.ibm.db2.jcc.c.gg.W(gg.java:457)
[4/5/07 10:21:54:560 MDT] 00000027 SystemErr     R       at com.ibm.db2.jcc.c.gg.executeUpdate(gg.java:440)
[4/5/07 10:21:54:560 MDT] 00000027 SystemErr     R       at com.arkona.Simple.doGet(Simple.java:49)
[4/5/07 10:21:54:560 MDT] 00000027 SystemErr     R       at javax.servlet.http.HttpServlet.service(HttpServlet.java:743)
[4/5/07 10:21:54:560 MDT] 00000027 SystemErr     R       at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
[4/5/07 10:21:54:560 MDT] 00000027 SystemErr     R       at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1212)
[4/5/07 10:21:54:560 MDT] 00000027 SystemErr     R       at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:629)
[4/5/07 10:21:54:561 MDT] 00000027 SystemErr     R       at com.ibm.ws.webcontainer.servlet.CacheServletWrapper.handleRequest(CacheServletWrapper.java:80)
[4/5/07 10:21:54:561 MDT] 00000027 SystemErr     R       at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:1657)
[4/5/07 10:21:54:561 MDT] 00000027 SystemErr     R       at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:77)
[4/5/07 10:21:54:561 MDT] 00000027 SystemErr     R       at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:421)
[4/5/07 10:21:54:561 MDT] 00000027 SystemErr     R       at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewInformation(HttpInboundLink.java:367)
[4/5/07 10:21:54:561 MDT] 00000027 SystemErr     R       at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.ready(HttpInboundLink.java:276)
[4/5/07 10:21:54:561 MDT] 00000027 SystemErr     R       at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.sendToDiscriminaters(NewConnectionInitialReadCallback.java:201)
[4/5/07 10:21:54:562 MDT] 00000027 SystemErr     R       at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.complete(NewConnectionInitialReadCallback.java:103)
[4/5/07 10:21:54:562 MDT] 00000027 SystemErr     R       at com.ibm.ws.tcp.channel.impl.WorkQueueManager.requestComplete(WorkQueueManager.java:548)
[4/5/07 10:21:54:562 MDT] 00000027 SystemErr     R       at com.ibm.ws.tcp.channel.impl.WorkQueueManager.attemptIO(WorkQueueManager.java:601)
[4/5/07 10:21:54:562 MDT] 00000027 SystemErr     R       at com.ibm.ws.tcp.channel.impl.WorkQueueManager.workerRun(WorkQueueManager.java:934)
[4/5/07 10:21:54:562 MDT] 00000027 SystemErr     R       at com.ibm.ws.tcp.channel.impl.WorkQueueManager$Worker.run(WorkQueueManager.java:1021)
[4/5/07 10:21:54:562 MDT] 00000027 SystemErr     R       at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1332)

I have check via sql command the insert  and it works

insert into dldata(companyid, license, firstname, lastname, address, city, state, zip) values ('ar3', '1233333', 'Test', 'User2', '10757 south', 'south jordan', 'ut', '64334')
DB20000I  The SQL command completed successfully.

again here is my servlet code

try{
                  
                  Class.forName("com.ibm.db2.jcc.DB2Driver").newInstance();
                Connection conn = DriverManager.getConnection("jdbc:db2://arkona-db2-dev.arkona.com:50001/ARKDLS","db2inst1", "arkona");
                  PreparedStatement ps = conn.prepareStatement("insert into DB2INST1.DLDATA(COMPANYID, LICENSE, FIRSTNAME, LASTNAME, ADDRESS, CITY, STATE, ZIP) values (?,?,?,?,?,?,?,?)");
                  ps.setString(1,rq.getParameter("CompanyID"));
                  ps.setString(2,rq.getParameter("License"));
                  ps.setString(3,rq.getParameter("FirstName"));
                  ps.setString(4,rq.getParameter("LastName"));
                  ps.setString(5,rq.getParameter("Address"));
                  ps.setString(6,rq.getParameter("City"));
                  ps.setString(7,rq.getParameter("State"));
                  ps.setString(8,rq.getParameter("Zip"));
                  ps.executeUpdate();
                  ps.close();
                  
                  // conn.commit();
            }
            catch(Exception e)
            {
             e.printStackTrace();
            }

not sure whats going on here.
0
 
jareddraperAuthor Commented:
Nevermind found it it was a typo in CompanyID
0
 
jareddraperAuthor Commented:
OK I am still at a loss on how to close the window after the submit when it calls the servlet. Any help would be great  
0
 
KuldeepchaturvediCommented:
after you have sucessfully written the entry in database.. lets put this code..

..
..
 ps.setString(8,rq.getParameter("Zip"));
                  ps.executeUpdate();
                  ps.close();

PrintWriter out = response.getWriter();
 out.println("<HTML>");
out.println("<head>");
out.println("<script>");
out.println("window.close();");
out.println("</script>");
out.println("<body></body>");
out.println("</head>");
out.println("</HTML>");
  }
            catch(Exception e)
            {
             e.printStackTrace();
            }

should do it


0
 
jareddraperAuthor Commented:
That you a ton I had to add one line to that code and will be able to test it in the morning as I have finally got it off my laptop and into our test server, here is what I added

ServletResponse response = null;
                  PrintWriter out = response.getWriter();
                  out.println("<HTML>");
                  out.println("<head>");
                  out.println("<script>");
                  out.println("window.close();");
                  out.println("</script>");
                  out.println("<body></body>");
                  out.println("</head>");
                  out.println("</HTML>");

Thank you so much for all the direction and help on how to do this it goes way beyond anything I thought would happen on this site. I am just going to pick 1 reply as the solution even every response helped get there. I will reply tomorrow and let you know if the code worked and how everything finally pieced together.

Again that you so much for all the help and direction on how to do this.
0
 
KuldeepchaturvediCommented:
>>>
ServletResponse response = null;
you dont have to do this line..
you should be using the parameter which came in your request..
(normally the naming convention is request, response)..
I think we used rq & rs as our variables)..

so instead of using response.getWriter();
use rs.getWriter();

0
 
jareddraperAuthor Commented:
you are correct I didn't even notice that last night fixed it this morning and I am getting ready to test now.
0
 
jareddraperAuthor Commented:
ok that didn't seem to work what did I miss?


                  ...
ps.setString(5, rq.getParameter("Address"));
                  ps.setString(6, rq.getParameter("City"));
                  ps.setString(7, rq.getParameter("State"));
                  ps.setString(8, rq.getParameter("Zip"));
                  ps.executeUpdate();
                  ps.close();

                  
                  PrintWriter out = rs.getWriter();
                  out.println("<HTML>");
                  out.println("<head>");
                  out.println("<script>");
                  out.println("window.close();");
                  out.println("</script>");
                  out.println("<body></body>");
                  out.println("</head>");
                  out.println("</HTML>");

                  // conn.commit();
            } catch (Exception e) {
                  e.printStackTrace();
            }
      }
0
 
KuldeepchaturvediCommented:
what is the result that you are getting? check if there is any popup blocker or a script blocker who is blocking the script.
also on the browser do a right click and view source.. see if our HTML is there on the browser
0
 
jareddraperAuthor Commented:
It opens the servlet and adds the information and I just have an empty firefox window.

This is the code when viewing right click view source

<HTML>
<head>
<script>
window.close();
</script>
<body></body>
</head>
</HTML>

I'm not blocking any popups and I allow javascript in firefox.
0
 
KuldeepchaturvediCommented:
Hmm strange... this should have closed the window...

if you type this as a plain HTML  and try to open up in browser what it does?
0
 
jareddraperAuthor Commented:
If I open it with firefox it opens a blank page but if I open it with konqueror it closes the window just like its supposed to. So its a setting in my firefox somewhere. Thank you so much for all the help with this. I learned alot about servlets and jsp's I will pick one of the answers here as the solution although every post you made here helped me greatly learn how to do this. Again thank you
0
 
jareddraperAuthor Commented:
weird thing I can get this to work in konqueror but not in firefox or IE of course those would be the browsers I need it to work in. Any idea's would be great
0
 
KuldeepchaturvediCommented:
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

  • 28
  • 17
Tackle projects and never again get stuck behind a technical roadblock.
Join Now