SQL INSERT problem - help please

Hello,
I'm having a problem with INSERT statement.
There is a "ShowFinal.jsp" page, which is a list of candidates who selected from the second
interview. The user picked some candidates from the list and conduct the 3rd interview. After
he check suitable candidates(who are selected from the 3rd interview) from the list , enter
basic salary for every selected candidate, enter date of interview and finally submit the form.
These data should be save into these tables.
FinalSelect(nicNo,date)
EmpSalary(nicNo,basicSal)
In this "ShowFinal.jsp" page, it validates the following conditions using JavaScript.
1) If the user submit the form without checking at least one checkbox, then the system should be
display an alert message ("Please select at least one candidate").
2) If the user submit the form without entering the basic salary of that candidate which was
checked, then the system should be display an alert message ("Please enter basic salary").
These are working well. But my problem is how to wrote the "AddNewFinal.jsp" page to save these
data into the db.
Here is my code which I have wrote. But it points an error.
"AddNewFinal.jsp"
String interviewDate = request.getParameter("date");
String[] value = request.getParameterValues("ChkNicno");
String[] bs = request.getParameterValues("basicSal");
String sql ="INSERT INTO finalselect (nicNo,date) VALUES(?,?)";
String sql2 ="INSERT INTO EmpSalary (nicNo,basicSal) VALUES(?,?)";
for(int i=0; i < value.length; i++){
     String temp = value;     
     for(int x=0; x < bs.length; x++){
          String basic = bs[x];
          pstmt2 = connection.prepareStatement(sql2);
          pstmt2.setString(1, temp);
          pstmt2.setString(2, basic);
          int RowCount1= pstmt2.executeUpdate();
     pstmt1 = connection.prepareStatement(sql);
     pstmt1.setString(1, temp);
     pstmt1.setString(2, interviewDate);
     int RowCount= pstmt1.executeUpdate();
Here is the code for "ShowFinal.jsp".
<form name="ShowFinal" method="POST" action="AddNewFinal.jsp" onsubmit="return checkEmpty() &&
ValidateDate();">
<%--  Loop through the list and print each item --%>
<%
     int iCounter = 0; //counter for incremental value
     while (igroups.hasNext()) {
          Selection s = (Selection) igroups.next();
          iCounter+=1; //increment
%>
<tr>
     <td style="background-color:ivory" noWrap width="20">
     <input type="checkbox" name="<%= "ChkNicno" + iCounter %>"      
value="<%=s.getNicno()%>"></td>
        <td style="background-color:ivory" noWrap width="39">
             <%= s.getNicno() %>  </td>
     <td style="background-color:ivory" noWrap width="174">
          <input type="text" name="<%= "basicSal" + iCounter %>" size="10"> </td>
</tr>
<%
%>
Date of interview<input type="text" name="date" size="17"></td>
<input type="submit" value="APPROVE CANDIDATE" name="B1" style="border: 1px solid #0000FF">
</form>........................................................
Here is the error generated by TOMCAT.
root cause
java.lang.NullPointerException
     at org.apache.jsp.AddNewFinal_jsp._jspService(AddNewFinal_jsp.java:70)
     at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:137)
I have goto the file "AddNewFinal_jsp.java". The line 70 points to the following line.
for(int i=0; i < value.length; i++){ [/b]
Please can someone help me to solve this problem? Please help me to do this task.
Thanks.

Hi Casabianca ,
It is clearly that your problem is not on the database end, more like a servlet/jsp issue.
I will not comment on the javascript portion, but rather the 2 jsps.
a simple way to trace what's go wrong is to check the final result (the html code) of the first jsp (showFinal.jsp), and compare against what is expected by the 2nd jsp (AddNewFinal.jsp). Most browser do provide "view source" on the page visited.
the following code
<input type="checkbox" name="<%= "ChkNicno" + iCounter %>" value="<%=s.getNicno() %>">
<input type="text" name="<%= "basicSal" + iCounter %>"
would likely to be "translated" to html code something as follow:
<input type="checkbox" name=""ChkNicno0" value="nicNo>">
<input type="text" name="basicSal0">
the original code in "AddNewFinal.jsp" using
request.getParameterValues("ChkNicno");
which looking for a none exist http request parameter (sent as "ChkNicno0",etc but look for "ChkNicno"), which has explained before.
the second attempt to use String[] value = request.getParameterValues("ChkNicno" + iCounter); give Cannot resolove symbol :iCounter. because iCounter never defined in the 2nd jsp!
Most of the error message do give clue to cause of error... : )
not too sure on your intension, assume you wish to update only those selected (checked) row to db.
some suggestions:
1) <input type="text" name="ChkNicno" size="10"> </td>...
<input type="text" name="basicSal" size="10"> instead.
then use javascript to based on checked element index (refer to javascript spec for more details), for those index not checked, clear off the correspond index "basicSal" field value.
e.g. ChkNicno[1] is not checked, empty basicSal[1] value before submission.
This will give us only selected rows values.
2) retain the code
String[] value = request.getParameterValues("ChkNicno");
String[] bs = request.getParameterValues("basicSal");at 2nd jsp, as now the http request will pass parameters using "ChkNicno" and "basicSal".
3) some change to the code for optimization
for(int i=0; i < value.length; i++){
     String temp = value;     
     for(int x=0; x < bs.length; x++){
          String basic = bs[x];
          pstmt2 = connection.prepareStatement(sql2);
          pstmt2.setString(1, temp);
          pstmt2.setString(2, basic);
          int RowCount1= pstmt2.executeUpdate();
     pstmt1 = connection.prepareStatement(sql);
     pstmt1.setString(1, temp);
     pstmt1.setString(2, interviewDate);
     int RowCount= pstmt1.executeUpdate();
to
pstmt1 = connection.prepareStatement(sql);
pstmt2 = connection.prepareStatement(sql2);
for(int i=0; i < value.length; i++){
     String temp = value;     
     for(int x=0; x < bs.length; x++){
          String basic = bs[x];
          pstmt2.setString(1, temp);
          pstmt2.setString(2, basic);
          int RowCount1= pstmt2.executeUpdate();
     pstmt1.setString(1, temp);
     pstmt1.setString(2, interviewDate);
     int RowCount= pstmt1.executeUpdate();
preparestatement created once should be sufficient as we do not change the sql statement throughout the loop.
there are better solutions out there, this just some ideas and suggestions.Do try out if you wish.
Hope it helps. : )

Similar Messages

  • SQL insert statement help please

    alternative is to have the table with field dateadd with default value of getdate()   - then do not include in your insert statement - then the modify date use and update - starting point - my two cetns

    Hi all I'm trying to go a little out of my comfort level here and was hoping for some advice. I have a sql table that has 2 date fields. an add and a modified. If the modified date is null then I want to calculate on the date added. Otherwise I'd like to calculate on the modified date.
    Here is a simplified version of what I'm trying to accomplish.
    Hope it makes sense what I'm trying to do.
    SQLSELECT field1,field2.... ,dateAdded , dateModifiedINTO tblOutputFROM tblInput/* some pseudo code here */WHERE (if dateModified not null then ( dateModified

  • Export "SQL Insert" problem

    Hello to everybody,
    I'm using SQL Developer 1.0.0.15.57 in an Italian Windows XP Professional SP2.
    I'm exporting a table as "SQL Insert" and I have the following problem: the exported INSERT instruction contains, i.e., 123,45 instead of 123.45 so, running the INSERT, Oracle 10 tells me too much values were given because
    Value1, 123,45, Value2, ...
    is wrong: it should be
    Value1, 123.45, Value2, ...
    I think this is a problem of the Internation settings (in Italy we use , as decimal separator instead of the . ). Does anybody know how to solve this?
    For the moment I have changed my Internal Settings with USA and, after arestart, this is fixed. However now there is another less heavy problem: the dates are written in English like to_date('01-JAN-06', ... instead of to_date('01-GEN-06', ... but I can fix it with a search&replace function.
    Thank you in advance
    Andrea

    Hello. I'm trying to find a solution for this too. In Venezuela we also use , as decimal separator. Has anybody found a solution for this? It is absolutly necesary to change the international settings of my pc?
    Thanks!
    Message was edited by:
    JeanK

  • VIRUS PROBLEMS, HELP PLEASE???

    I continue to have messages popping up saying my computer is infected. It wants me to cleanup and I have to register with Mac Shield 2.6.  Pronograhic websites keep popping up.  Anyone having this problem?  Did not have this problem yesterday, but it's here today!  There is also a Red Sheild on the top of the toolbar where it shows the time, battery life, etc.  Right clicking on the sheild drops down Scan Now, Cleanup, Control Center, Scan, System Info, Settings, About, and Register.  A pron site just popped up again!  Need help Please!!

    Fuony wrote:
    The Mac Shield malware can come through Firefox too if you allow it to and you click on it!
    Your exactly right, it is possible that if you visit a site and need the scripts to run for something that the malware that uses Javascript is on that site, then your going to be presented with it.
    The thing is with the Firefox + NoScript combination defeats alot of the web side trickery the malware authors are using to get the malware to appear in the first place.
    Also this "MacDefender" isn't the only malware making the rounds. There are some serious Flash vulnerabilities being hosted on hostile/adult websites that are running scripts for no apparent reason other than to try to infect your machine.
    By running all scripts all the time, your computer is in a state as if you tried running across a busy highway blindfolded.
    As a lifelong "MacHead" I can understand Apple loyalty, but if Apple isn't cutting the mustard on their browser security, rather place their users security at serious risk for the sake of convenience, then I have to think about using and recommending to others something else that is more secure.
    As a example, I surf thousands of web pages a day, some on really nasty sites, yet I haven't seen this "MacDefender" appear on my computer. Even when I purposely visited links that people have submitted that had the malware. (I maintain a couple of bootable clones of my boot drive just in case)

  • ICloud problems help please!

    I have an iPhone 6 and during the setup I must have did something wrong and now I have my old iCloud account on it that I no longer remember the password, security questions, and no longer have the email address to that account.  I think I was hacked and my password and security questions changed. I want to log out of iCloud and start using my current iCloud account.  I know these are security measures, but how can I get logged out??? My iPhone is having problems since the latest update and now I can't make a call or text.  I can't call apple support without a working number  HELP Please.

    Hello shelbyrecords,
    Oh no! That sounds really frustrating. Unfortunately, if iCloud Find my iPhone Activation Lock is enabled on the device we’ll need to gain access to your previous Apple ID account to disable it. Based on the information you have provided, it sounds like you may need a personalized support experience to recover your previous Apple ID:
    If you forgot your Apple ID password - Apple Support
    http://support.apple.com/en-us/HT201487
    Make sure that you’re entering the correct Apple ID. In most cases, your Apple ID is also the primary email address of your Apple ID account. If these steps didn't help you change your password, contact Apple Support.
    Thanks,
    Matt M.

  • Soundtrack problems - help please

    Help please. I tried doing a send to multi-track project from FCP with the base layer video option and kept getting the 'error sending selection to Soundtrack Pro' message. I did a search and the suggestion is that I have no disk space but I have over 600GB!
    Then I tried a send with the full video and the file saved okay. However when I try to open the .stmp file, Soundtrack Pro starts and then freezes. I've tried opening in various ways.
    Help please, I just cannot figure this out! What am I doing wrong?

    Not sure how much help this is, but since you're having problems with the layout, did you try deleting the layout file? MacintoshHD/users/username/Library/Application Support/Soundtrack Pro/Layouts
    BTW, I found a BKiLifeConfiguration.plist in the following path:
    MacintoshHD > Library > Application Support > ProApps > Internal Plug-ins > BrowserKit > iLife.bkplugin > Contents > Resources
    Do you find it there?

  • Multiselect problem Help please!!

    Hi all,
    I am currently using Application Express 3.1.2.00.02 I have developed an online questionnaire with a multiselect list for one of the questions. The problem i am having is that i need each choice to be totaled up separately on the report generated.
    My table of answers looks like this:
    Column name e.g. (Question 9)
    Answer "Dog" "Cat" "Mouse" "Snake" (underneath column name Question 9 depending on what is selected).
    The reporting page would look like below:
    *(Column Question 9)* Count
    Dog 1
    Mouse 1
    Snake 1
    and for the question you could have another respondent who chooses similar of items on the multiselect, so their answer looks like this:
    Answer
    "Question 9" Dog
    "Question 9" Snake
    This would then start a new row on the reporting page like below which is not what i want:
    *(Column Question 9)* Count
    Dog 1
    Mouse 1
    Snake 1
    Dog: Snake 1
    But the report should look like this:
    *(Column Question 9)* Count
    Dog 2
    Mouse 1
    Snake 2
    The current SQLquery i am using is below:
    select "QUESTION 9",
    count(*) c
    from "P1 DQUESTIONNAIRE"
    group by "QUESTION 9"
    Thanks for your help and suggestions,
    'S'

    How to make sure your forum post will never be answered:
    1) Make sure your subject line is completely meaningless (i.e. HELP PLEASE!) and describes no part of your actual problem
    2) State that you are having "a few problems" but make sure to offer no details whatsoever what those problems are or what the symptoms are.
    3) Post large volumes of code instead of distilling the problem down to a compact snippet
    4) For extra points, make the code hard to read by refusing to make use of the "code" tag.

  • K8N Neo2-fx Ram problem Help please

    I have three ram(2x512MB single sided , 1x1GB double sided). Is there any way I can put them all on the motherboard? When I place them all the computer is not starting and it`s making a "beep" every 2-3 seconds. If i connect the 1GB double sided on the Dimm1(green) and the one 512MB single sided on the Dimm3(green) it`s working properly. Is there any way I can use all my ram at the same time. I`m desperate. Help please...  thank you

    Quote from: wodahS on 09-November-06, 05:55:17
    How can I put my computer facts under any post I am posting? I should make it my signature?
    That's the rule mate which you need to gives all your component in details including your PSU and Bios revision so that others can help you! Like what BOSSKILLER say it won't works with 3 DIMMS unless you purhased another 1 GB of RAM then it can solve your problem with 4 DIMMS or else with 2*512MB RAM. Make sure that you've lowered your HT to <=800Mhz as default is 1000Mhz. GD luck.

  • SQL 2.0 and CVI 5.5 Problem - Help please!

    Hi All,
    I have recently updated to CVI 5.5. Over the last week I have been update
    my programs to 5.5. However, I am having problems with the SQL toolbox -
    more specifically the "DBImmediateSQL" function. When the line of code runs
    which contains this function, it returns the error code -11, and an
    Automation Error code -2147352573, Unknown error.
    I am stuck, as this program has been running in 5.0.1 for about a year.
    Does anyone have any idea what could be wrong?
    Richard

    Bill,
    After some discussion with the folk from NI, we discovered that it was
    caused by the installation of SP4 for MSVS. I found I had to reverse all
    changes made by this upgrade to the OBDC and database access. Once this was
    done, I reloaded an older version and things worked fine.
    Sorry for the delay in replying - been on holidays.
    Richard
    "Bill Groenwald" wrote in message
    news:[email protected]..
    >
    > Richard,
    > I don't have an answer but maybe a clue. I am still running 5.0.1 and have
    > just run into the same problem. I'm suspecting a recent install of a
    software
    > inventory management package effected some Oracle library file that
    LabWindows
    > goes through. I found that if I switched to the DBActivateSQL for my
    insert,
    > that worked. I have asked support what could allow DBActivateSQL to work
    > and DBImmediateSQL to fail but have no answer yet. If you can, try that
    workaround
    > to see if it helps. Good Luck.
    > Bill Groenwald
    >

  • Hibernate-very strange problem, help please

    Hi, i got such a strange problem that im sure you ll think im doin crazy talk :) , i dont see why this would happen at all, i have a class called "Package", mapped to a table "package". whenever i do a query on this table using hibernate, even the simplest "find all" kinda of query, hibernate does update on the table b4 doin the query! even more weird, it does the update when the first query on this table happens, it deletes all values of a column (yes only this column); then if i do the same query again, no update at all. however if now i mannuall add those missing values, it does the update again and deletes them! sry its confusing, heres my code and more of wat i done:
    The mapping Package.hbm.xml
    <hibernate-mapping package="tuition.bo">
    <class name="Package" table="package">
    <id name="id" column="study_package_id" type="long">
    <generator class="sequence"/>
    </id>
    <property name="name" column="name" not-null="true"/>
    <property name="satTiming" column="sat_timing" not-null="false"/>
    <property name="satSubjects" column="sat_subjects" not-null="false"/>
    <property name="sunTiming" column="sun_timing" not-null="false"/>
    <property name="sunSubjects" column="sun_subjects" not-null="false"/>
    <set name="classes" inverse="true" cascade="delete-orphan" lazy="true">
    <key column="package_id"/>
    <one-to-many class="Class"/>
    </set>
    </class>
    </hibernate-mapping>
    For example initialy i populated database using hibernate, like this:
    package_id, name, sat_timing, sat_subjects, sun_timing, sun_subjects
    1 no.1 9-12 business 9-12 law
    2 no.2 9-11 business 9-11 law
    Then after i populated this database, i did this query:
    <b>List res=getHibernateTemplate().find("FROM Package");</b>
    and you can see the log file as such: (excerpt)
    16:23:06,687 INFO TransactionFactoryFactory:31 - Using default transaction strategy (direct JDBC transactions)
    16:23:06,703 INFO TransactionManagerLookupFactory:33 - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
    16:23:09,968 DEBUG JDBCTransaction:46 - begin
    16:23:09,968 DEBUG JDBCTransaction:50 - current autocommit status: true
    16:23:09,968 DEBUG JDBCTransaction:52 - disabling autocommit
    <b>16:23:10,640 DEBUG SQL:324 - select</b> studypacka0_.study_package_id as study1_, studypacka0_.name as name12_, studypacka0_.description as descript3_12_, ....... from _3AT_package studypacka0_
    Hibernate: select studypacka0_.study_package_id as study1_, studypacka0_.name as name12_, studypacka0_.description as descript3_12_, studypacka0_.day as day12_, studypacka0_.sat_timing as sat5_12_, studypacka0_.sat_subjects as sat6_12_, .......
    16:23:10,734 DEBUG JDBCTransaction:83 - commit
    <b>16:23:10,796 DEBUG SQL:324 - update</b> _3AT_package set name=?, description=?, day=?, sat_timing=?, sat_subjects=?, sat_hours=?, sun_timing=?, sun_subjects=?, sun_hours=?, unit_price=?, years_id=?, group_id=? where study_package_id=?
    Hibernate: update _3AT_package set name=?, description=?, day=?, sat_timing=?, sat_subjects=?, sat_hours=?, sun_timing=?, sun_subjects=?, sun_hours=?, unit_price=?, years_id=?, group_id=? where study_package_id=?
    <b>16:23:10,812 DEBUG SQL:324 - update </b>_3AT_package set name=?, description=?, day=?, sat_timing=?, sat_subjects=?, sat_hours=?, sun_timing=?, sun_subjects=?, sun_hours=?, unit_price=?, years_id=?, group_id=? where study_package_id=?
    Hibernate: update _3AT_package set name=?, description=?, day=?, sat_timing=?, sat_subjects=?, sat_hours=?, sun_timing=?, sun_subjects=?, sun_hours=?, unit_price=?, years_id=?, group_id=? where study_package_id=?
    <b>16:23:10,812 DEBUG SQL:324 - update</b> _3AT_package set name=?, description=?,
    16:23:10,953 DEBUG JDBCTransaction:173 - re-enabling autocommit
    16:23:10,953 DEBUG JDBCTransaction:96 - committed JDBC Connection
    as you can see, it does update and changed table field values to this:
    package_id, name, sat_timing, sat_subjects, sun_timing, sun_subjects
    1 no.1 business law
    2 no.2 business law
    ---------- all tiimings are gone. and now if i re-do the same query, there are NO UPDATE operations....howver if i add some values to sat_timing, sun_timing, and re-do the query, very surprisingly, i saw those update operations which delete all timing values again!
    im totally lost... i havent changed any config, this doenst happen to my other classes at all but just this one.... any ideas please! even some thought of what may caused this would be great help! thank you!

    well i got the setters wrong.... being so stupid i am... sry for creating such a long and massy thread.

  • Mildet connect to oracle DB using servlet problem ,help please

    hi guys i have a problem am tring to connect my midlet to databse through midlet but i don`t know what is the problem so far the midlet already connect to my servlet url but the servlet cant read the parameters to open the connection for database
    my servlet code
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    import java.io.*;
    import java.net.*;
    import java.sql.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.text.*;
    * @author freddy
    public class getconnection extends HttpServlet {
        Statement statement;
    ResultSet rs=null;
    String bstr=null;
    String bstr1=null;
    String bstr2=null;
    public void init()
        * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
        * @param request servlet request
        * @param response servlet response
        protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
            response.setContentType("text/html;charset=UTF-8");
            PrintWriter out = response.getWriter();
            try {
                /* TODO output your page here
                out.println("<html>");
                out.println("<head>");
                out.println("<title>Servlet getConnection</title>"); 
                out.println("</head>");
                out.println("<body>");
                out.println("<h1>Servlet getConnection at " + request.getContextPath () + "</h1>");
                out.println("</body>");
                out.println("</html>");
            } finally {
                out.close();
        // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
        * Handles the HTTP <code>GET</code> method.
        * @param request servlet request
        * @param response servlet response
        @Override
        protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
            processRequest(request, response);
      doPost(request,response);
        * Handles the HTTP <code>POST</code> method.
        * @param request servlet request
        * @param response servlet response
        @Override
        protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
            processRequest(request, response);
            DataInputStream in = new DataInputStream(
                    (InputStream)request.getInputStream());
            String sid = in.readUTF();
            String user = in.readUTF();
            String pwd = in.readUTF();
          //  "jdbc:oracle:thin:@localhost:1521"+": "+sid
            String message = message = "Name:"+bstr+" telephone:"+bstr1+" burthday:"+bstr2;
             try {
                connect(sid,user, pwd);
                message += "100 ok connected";
            } catch (Throwable t) {
                message += "200 " + t.toString();
            response.setContentType("text/plain");
            response.setContentLength(message.length());
            PrintWriter out = response.getWriter();
            out.println(message);
            in.close();
            out.close();
            out.flush();
        private void connect(String sid, String user,String pwd)
        throws Exception {
            // Establish a JDBC connection to the MYSQL database server.
            //Class.forName("org.gjt.mm.mysql.Driver");
            Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
            Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:"+sid,user,pwd);
            System.out.print("connected");
            try{
               statement =conn.createStatement();
                rs=statement.executeQuery(" Select*from WOH.P_DEMGRAPHICS where P_ID='P1000 '");
            catch(SQLException e)
            System.err.print(e);
           try{
    while (rs.next()) {
    bstr=rs.getString(2);
    bstr1=rs.getString(3);
    bstr2=rs.getString(4);
    statement.close();
       catch (SQLException e) {
    //bstr += e.toString();
    System.err.println(e);
    System.exit(1);
            // Establish a JDBC connection to the Oracle database server.
            //DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
            //Connection conn = DriverManager.getConnection(
            //      "jdbc:oracle:thin:@localhost:1521:"+db,user,pwd);
            // Establish a JDBC connection to the SQL database server.
            //Class.forName("net.sourceforge.jtds.jdbc.Driver");
            //Connection conn = DriverManager.getConnection(
            //      "jdbc:jtds:sqlserver://localhost:1433/"+db,user,pwd);
        * Returns a short description of the servlet.
        public String getServletInfo() {
            return "Short description";
        // </editor-fold>
    }Midlet code
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    import java.io.*;
    import java.util.*;
    import javax.microedition.io.*;
    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    * @author freddy
    public class testOrcl extends MIDlet  implements CommandListener {
       protected String url;
        private String username;
        private Display display;
        private Command exit = new Command("EXIT", Command.EXIT, 1);;
        private Command connect = new Command("Connect", Command.SCREEN, 1);
        private TextField tb;
        private Form menu;
        private TextField tb1;
        private TextField tb2;
        DB db;
        public testOrcl() throws Exception
            display=Display.getDisplay(this);
            url="http://localhost:8084/getConnection/getconnection";
        public void startApp() {
            displayMenu();
        public void displayMenu()
        menu= new Form("connect");
         tb = new TextField("Please input database: ","",30,
                    TextField.ANY );
            tb1 = new TextField("Please input username: ","",30,
                    TextField.ANY);
            tb2 = new TextField("Please input password: ","",30,
                    TextField.PASSWORD);
            menu.append(tb);
            menu.append(tb1);
            menu.append(tb2);
            menu.addCommand(exit);
            menu.addCommand(connect);
            menu.setCommandListener(this);
            display.setCurrent(menu);
        public void pauseApp() {
        public void destroyApp(boolean unconditional) { }
        public void commandAction(Command command, Displayable screen) {
            if (command == exit) {
                destroyApp(false);
                notifyDestroyed();
            } else if (command == connect) {
                db  = new DB(this);
                db.start();
                db.connectDb(tb.getString(),tb1.getString(),tb2.getString());
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    import java.io.*;
    import java.util.*;
    import javax.microedition.io.*;
    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    import java.lang.*;
    * @author freddy
    public class DB implements Runnable  {
        testOrcl midlet;
         private Display display;
            String sid;
            String user;
            String pwd;
            public DB( testOrcl midlet)
            this.midlet=midlet;
            display=Display.getDisplay(midlet);
        public void start()
        Thread t = new Thread(this);
                t.start();
        public void run()
         StringBuffer sb = new StringBuffer();
                try {
                    HttpConnection c = (HttpConnection) Connector.open(midlet.url);
                   c.setRequestProperty(
                       "User-Agent","Profile/MIDP-2.1, Configuration/CLDC-1.1");
                    c.setRequestProperty("Content-Language","en-US");
                    c.setRequestMethod(HttpConnection.POST);
                    DataOutputStream os =
                            (DataOutputStream)c.openDataOutputStream();
                    os.writeUTF(sid.trim());
                    os.writeUTF(user.trim());
                    os.writeUTF(pwd.trim());
                    os.flush();
                    os.close();
                    // Get the response from the servlet page.
                    DataInputStream is =(DataInputStream)c.openDataInputStream();
                    //is = c.openInputStream();
                    int ch;
                    sb = new StringBuffer();
                    while ((ch = is.read()) != -1) {
                        sb.append((char)ch);
               showAlert(sb.toString());
                    is.close();
                    c.close();
                } catch (Exception e) {
                    showAlert(e.getMessage());
         /* This method takes input from user like db,user and pwd and pass
                to servlet */
            public void connectDb(String sid,String user,String pwd) {
                this.sid = sid;
                this.user = user;
                this.pwd = pwd;
            /* Display Error On screen*/
            private void showAlert(String err) {
                Alert a = new Alert("");
                a.setString(err);
                a.setTimeout(Alert.FOREVER);
                display.setCurrent(a);
       

    Comment out process request or rewrite & move it to a position after you read the parameters and connect to the db. Decide where you want to write to the output stream. Also, you have some superfluous casting.
    I take it that you are using netbeans? If you debug and step through the code you will get an idea of the flow. The steps should be, midlet connects with POST, doPost is called, server reads parameters, server opens connection, executes query, releases/closes connection, and writes a response to the midlet.
    Some notes about the connect method; The scope of rs may cause problems. It is unlike you will have a valid result set if you have a problem with create statement or execute. Take a look at connection pooling and be mindful how the connections are opened, used, and closed; put all the important cleanup operations in a finally. Remove system.exit from your servlet. Actually I would suggest limiting the scope of all your vars;
    If you store the username, password, and sid on the midlet, you may have trouble updating the installation base if you need to change the values for any reason. Also, you have clients which contain your database u/p, susceptible to snooping and decompilation. Use the servlet to abstract the db from the client. And use a datasource (with connection pooling) for obtaining connections to db.

  • Sql - Insert problem in MsAccess

    Hello!!!
    J have problem with INSERT function, I use MsAccessm as database. My query is :
    INSERT INTO [Produkty-www] ( Id,Nazwa,Kod,Cena)
    VALUES 6646545,"Zlaczka
    prosta 22mm 1/2 ' z (KRoCIEC)",'JGK22-1/2Z',10.00)
    this is very import symbol ' in 1/2 ' z must be at the place. When I execute this query I have exception. In maaccess I create query and also msaccesse show me when is the bad part of query the sybmol ' is underline.
    So I create a new query but in access :
    INSERT INTO [Produkty-www] ( Id,Nazwa,Kod,Cena) VALUES (6646545,"Zlaczka prosta 22mm 1/2 ' z (KRoCIEC)",'JGK22-1/2Z',10.00)
    and ok access add record, now I copy this query to my java application and I also have exception.
    Why this query don`t work.. ?

    Ok, it`s done :     
    PreparedStatement statement = podlaczenie.prepareStatement("INSERT INTO [Produkty-www] (id, Nazwa, Kod, Cena) VALUES (?,?,?,?)");
    statement.setInt(1,2);
    statement.setString(2,"ffsdfds'fdsfs");
    statement.setString(3,"kod");
    statement.setInt(4,124);
    statement.execute();
    But I need a sql query print to console, a search a method of statement but I dont find that I look for, it is some method that give my sql query in string ?
    Thank`s for help

  • Shockwave Player 11 - Problem HELP PLEASE!!

    I have upgraded to Shockwave Player 11 but I am having big
    problems. I have installed it but when going on a Shockwave
    supported sites ie; iSketch, it comes up in a white-box with a
    message ''Adobe Shockwave Player is now installing.'' ''Installing
    compatibility components.'' with a white bar below which is
    supposed to fill up but doesnt. Screenshot on Link below. I have
    been trying it both on IE7 & Firefox, tried both semi and full
    installer but no luck. Please help?
    http://i7.photobucket.com/albums/y295/ldndude/others/ShockwaveFlash11Problem.jpg

    quote:
    This worked for me. It will actually let me access the game,
    but it is unplayable. The drawings are all just random lines. When
    I draw people see this problem, it looks like I am just drawing
    random lines on the canvas.
    I'm glad 4 helping u.4 me all the games r playable.But the
    new ones like....
    http://www.miniclip.com/games/power-boat/en/
    or
    http://www.miniclip.com/games/rally-championship/en/
    r very slow.

  • I'm having trouble printing playlist inserts.  Help please.

    I have never had this problem before. when printing a playlist insert, all printing is running together. A friend told me he is getting the same thing. I recently downloaded the latest itunes version. Is the problem on my end or your end. Thanks for your help.

    This is the iPhoto 08 forum and has nothing to do with Mail or Gmail. I suggest you find a Gmail user's forum or ask in the Mail forum.
    OT

  • How do I solve the following Itunes error -42404 I have tried uninstalling as well as repair and re installing, I keep getting the same problem, Help please

    Please help I am un able to get my I Tunes back on my Windows 7 -64 after a Virus clean out, How can I solve a problem with the followin ITunes error of -42404 I have tried the usual uninstall and reinstal, as well as the  repair all at no success, do any of you have any solution Ideas that have solved this in the past? Please Help, Thank you...

    For general advice see Troubleshooting issues with iTunes for Windows updates.
    The steps in the second box are a guide to removing everything related to iTunes and then rebuilding it which is often a good starting point unless the symptoms indicate a more specific approach. Review the other boxes and the list of support documents further down page in case one of them applies.
    Your library should be unaffected by these steps but there is backup and recovery advice elsewhere in the user tip.
    If you've already tried a complete uninstall and reinstall try opening iTunes in safe mode (hold down CTRL+SHIFT as you start iTunes) then going to Edit > Preferences > Store and turning off Show iTunes in the Cloud purchases. You may find iTunes will now start normally.
    tt2

Maybe you are looking for