Need help regarding executeUpdate() for my database

i am trying to update my database and set the records to false... althought it can execute, my records are still not changed according.. help appreciated !!
import java.io.*;
public class Index {
     private static String mTitle = "";
public Index() {
public static void main(String[] args)throws IOException {
// TODO code application logic here
System.out.println("===Start===");
Dbc dbc = new Dbc();
if(dbc.setCon()==0)
     System.out.println("Database load successful...");
else{
     System.out.println("Database load unsuccessful...");
     System.exit(1);
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
while(mTitle.length()<1 | mTitle==""){
     System.out.print("Enter movie title: ");
     mTitle = input.readLine();
     if(mTitle.length() > 0 && mTitle!=""){
          //System.out.println("You have entered: \"" + mTitle + "\"");
          System.out.println("Searching database...");
          int searchStatus = 0;
          searchStatus = dbc.readData(mTitle);
          if(searchStatus==0 && mTitle!=""){
               mTitle = "";
               System.out.println("Movie title not found...\n");
                    }else if(searchStatus==2 || searchStatus==3){
                         mTitle = "";
     }else
                    System.out.println("Please enter a valid movie title...\n");
System.out.println("===End===");
import java.sql.*;
import java.io.*;
public class Dbc{
     private Connection con;
     private boolean status;
     final static private String _driver = "sun.jdbc.odbc.JdbcOdbcDriver";
     final static private String dsn = "database";
     final static private String _user = "";
     final static private String _pass = "";
     final static private String _url = "jdbc:odbc:";
     //Establish database connection
     public int setCon(){
          // load the database driver
          try {
          Class.forName(_driver);
          catch (Exception e) {
               System.out.println("Load driver error");
               System.exit(1);
          //after loading the driver, establish a connection
          try {
               String s = _url + dsn;
               con = DriverManager.getConnection(s, user, pass);
               //System.out.println("connection is " + s);
          catch (Exception e) {
               e.printStackTrace();
               System.exit(1);
          return 0;
     public int readData(String title)throws IOException{
          ResultSet mTitle = null;
          ResultSet cost = null;
          ResultSet loanStatus = null;
          ResultSet mId = null;
          ResultSet ctg = null;
          try{
               Statement stmt1 = con.createStatement();
               Statement stmt2 = con.createStatement();
               Statement stmt3 = con.createStatement();
               Statement stmt4 = con.createStatement();
               Statement stmt5 = con.createStatement();
               Statement stmt6 = con.createStatement();
               mTitle = stmt1.executeQuery("SELECT MovieTitle FROM Table1 WHERE MovieTitle LIKE '%" + title + "%'");
               cost = stmt2.executeQuery("SELECT Cost FROM Table1 WHERE MovieTitle LIKE '%" + title + "%'");
               loanStatus = stmt3.executeQuery("SELECT LoanStatus FROM Table1 WHERE MovieTitle LIKE '%" + title + "%'");
               mId = stmt4.executeQuery("SELECT CatalogueNo FROM Table1 WHERE MovieTitle LIKE '%" + title + "%'");
               ctg = stmt5.executeQuery("SELECT Category FROM Table1 WHERE MovieTitle LIKE '%" + title + "%'");
               int num = 0;
               while(mTitle.next() && cost.next() && loanStatus.next() && mId.next() && ctg.next()){
                    status = loanStatus.getBoolean("LoanStatus");
                    System.out.println("=== Listing " + (num+1) + " ===");
                    System.out.println("Movie title: " + mTitle.getString("MovieTitle"));
                    System.out.println("Movie ID: " + mId.getString("CatalogueNo"));
                    System.out.println("Category: " + ctg.getString("Category"));
                    System.out.println("Rental price per day: SGD$" + cost.getInt("Cost"));
                    System.out.println("Availability: " + status);
                    System.out.println("===========================\n");
                    //stmt6.executeUpdate("UPDATE Table1 SET LoanStatus=false WHERE MovieTitle LIKE '%" + title + "%'");
                    num++;
               /*stmt1.close();
               stmt2.close();
               stmt3.close();
               stmt4.close();
               stmt5.close();*/
               if(num>0){
                    BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
                    if(num==1){
                         String string = "";
                         char choice;
                         while(string.equals("")){
                              System.out.print("Do you want to rent this movie? <Y/N> ");
                              string = input.readLine();
                              string = string.toLowerCase();
                              if(string.length() == 1 && string.charAt(0) == 'y'){               if(status){
                                        stmt6.executeUpdate("UPDATE Table1 SET LoanStatus=false WHERE MovieTitle LIKE '%" + title + "%'");
                                        }else{
                                             System.out.println("Sorry, DVD unavailable...");
                                             return 2;
                                   }else if(string.length() == 1 && string.charAt(0) == 'n'){
                                        return 2;
                                        }else{
                                             string = "";
                         }else if(num>1){
                              return 3;
                    return 1;
               catch(java.sql.SQLException e){
                    System.out.println(e.toString());
               return 0;
     }

Here's some ideas:
You dont need multiple statements and resultSets. Just one of each. Between reuse, close the statement and resultSet . Use each resultSet to read the data into a collection and then get your data out of the collection. Dont work directly with the resultSet. Also, instead of
"select name1 from person where personID=1234"
"select name2 from person where personID=1234"
you can combine them into one:
"select name1,name2 from person where personID=1234"
This line will not run because its commented out:
//stmt6.executeUpdate("UPDATE Table1 SET LoanStatus=false WHERE MovieTitle LIKE '%" + title + "%'");
Put System.out.println() above this line to print out the values of each
item in the if statement to see if stmt6 runs.
if(string.length() == 1 && string.charAt(0) == 'y'){ if(status){
stmt6.executeUpdate("UPDATE Table1 SET LoanStatus=false WHERE MovieTitle LIKE '%" + title + "%'");
This line is not good because it assumes mTitle, cost, loanStatus, etc
are all the same size list. They may be of different sizes.
while(mTitle.next() && cost.next() && loanStatus.next() && mId.next() && ctg.next()){
Statements and resultSets should be closed in a try/catch/finally block.
Also, see my example on:
http://forum.java.sun.com/thread.jspa?threadID=5193839&messageID=9769059#9769059

Similar Messages

  • Need help JDBC conncetion for local database

    I have installed Oracle 8i home version on PC. I'm trying to access my database using JDBC, but I'm having problems with JDBC. How do I connect to the local database. Please post me the coding for that.
    Thanks
    my email address is - [email protected]

    http://otn.oracle.com/docs/products/oracle9i/doc_library/release2/java.920/a96654/basic.htm#1003303

  • Hey guys need help regarding iTunes U. My school is moving for iOS and Mac in the classroom and I have been appointed Junior Administrator for the schools technical department and integrating these devices into the classroom.

    Hey guys need help regarding iTunes U. My school is moving for iOS and Mac in the classroom and I have been appointed Junior Administrator for the schools technical department and integrating these devices into the classroom.
    I have an appointment with a director on Tuesday. I want to demo iTunes U. Problem is I have never used it before and have no idea how to set it up and even if I should sign up.
    Please help any ideas regarding iTunes U and how I should direct the meeting tomorrow.
    Please please post here.
    Thanks
    Tiaan

    Greetings fcit@!A,
    After reviewing your post, it sounds like you are not able to select none as your payment type. I would recommend that you read this article, it may be able to help the issue.
    Why can’t I select None when I edit my Apple ID payment information? - Apple Support
    Thanks for using Apple Support Communities.
    Take care,
    Mario

  • Need HELP regarding installinfg CR2008/Visual Advantage

    I need help regarding installing CR2008/Visual Advantage. I had the evaluation copy of cr2008. My compnay purchased the CR2008 Visual Advantage. Upon calling your customer service, I was told that I had to UN-install the CR2008 evaluation copy then install the CR2008. I did the unstall HOWEVER, when I try to install the CR2008 that we purchased, i get the following error..HR
    HR -2147024770-"c:\program files\business objects enterprise 12.0\win32_x86\REPORTCONVTOOL.DLL FAILED TO REGISTER"..
    I get more that just that one...I have received this before and based upon this formum, i have delted the regristry in the following using regedit.exe
    HKEY_LOCAL_MACHINE\SOFTWARE\BUSINESS OBJECT ;
    HKEY_CURRENT_USER\SOFTWARE\BUSINESS OBJECTS..
    Afeter i deleted the keys, I re-boot my pc and try to install the coftware again...BUT I GET THE SAME ERRORS...I have tryied this several times....what am i missing/not doing correctly

    Hi Shamish
    Actually you were on the right track, i think you just have to increase PSAPTEMP a bit and you will be fine. 358 MB seems just too small, i suggest you increase it to at least 2GB.
    1. what will be the difference in use of PSAPUNDO and PSAPTEMP while copy is running. ( i.e. what will be entered in PSAPUNDO and what will be filled in PSAPTEMP.)
    PSAPTEMP: is needed for large sort operations, as mentioned when you have a select with an ORDER BY clause, or if you do join two tables. During the client copy some sorting might be needed for special tables (cluster tables) where data is stored sorted.
    PSAPUNDO: undo space is only needed for DML (data manipulation), if data is changed undo is generated. This obviously is heavily the case during a client copy.
    2. the target client already has a copy taken 1 month before. so I think while importing it first delete existing data and then copies the new one.
    So If I first delete the target client and then take import on it; will it have advantage in regards of getiing UNDO or TEMP segments getting filled ?
    Deleting the client first might help for the undo problem, but you already solved that. I cannot imagine, it will help for the PSAPTEMP issue. As i said i would just increase PSAPTEMP and restart the copy.
    One more add: if you are doing the client copy with parallel processes, this will influence your requirements on temp and undo space, because of the concurrently running processes.
    Best regards
    Michael

  • Need Help Regarding JAVA BEAN

    Is any one tell me that JAVA BEAN only used in WEB or also you in Desktop applications???? and aslo tell how i implement Java class and use JAVA BEAN. I need help regarding above matter
    thanks in advance
    Rehan MIrza

    Here is a good link that indicate that JavaBean is not only for applets
    http://java.sun.com/docs/books/tutorial/javabeans/whatis/beanDefinition.html
    quote:
    The JavaBeans API makes it possible to write component software in the Java programming language. Components are self-contained, reusable software units that can be visually composed into composite components, applets, applications, and servlets using visual application builder tools. JavaBean components are known as Beans.
    Francois

  • I need help regarding installation of Netweaver 2004s

    Hi,
    I need help regarding installation of Netweaver. When ever i am running setup.exe, i am getting a page asking for local host and port number as 21212. When I enter my local host name and the port number as 21200 i am getting the error message given below and the installation stops. I am not able to proceed further. can any one help me what i need to do here. I created MS lookupadapter and entered my static ip address in 'host' file after 127.0.0.1 localhost and i disabled port number 3201 in system file. I verified system variables also. Everything is fine. I dont have firewall or antivirus installed in my system. Is there any thing else i need to do. please help me. Thanks in advance.
    " SAPinst is getting started.
    Please be patient ...
    starting gui server process:
      sapinstport: 21200
      guiport    : 21212
      guistart   : true
      command    : "C:\j2sdk1.4.2_09/bin\javaw.exe" -cp "C:/DOCUME1/ADMINI1/LOCALS1/Temp/sapinst_exe.6496.1162659801\jar\instgui.jar;C:/DOCUME1/ADMINI1/LOCALS1/Temp/sapinst_exe.6496.1162659801\jar\inqmyxml.jar" -Xmx256M -Dsun.java2d.noddraw=true SDTServer config=jar:sdtserver.xml guiport=21212 sapinsthost=localhost sapinstport=21200 guistart=true
    load resource pool G:\SAP\Softwares\IDES mySAP2005\51031898\IM_WINDOWS_I386\resourcepool.xml
    guiengine: no GUI connected; waiting for a connection on host (local hostname) , port 21200 to continue with the installation
    guiengine: login in process...............................
    guiengine: login timeout; the client was unable to establish a valid connection
    Exit status of child: 1"
    Regards,
    Farooq Shaik.

    Hi
    Run the sapinst.exe with the port 21212.This port 21212 is the default port used during the installation of netweaver.

  • Need Help regarding text Output

    Dear gurus.
    I need help regarding formatting of a text.
    I want to format a employee sub group text.
    im getting a text workers (7) from a table t503t having field ptext.
    i want to show only (7) in the output not the whole text how can i do this ?
    Please help
    regards
    Saad.Nisar

    DATA: BEGIN OF itab_odoe OCCURS 0,
      department_text LIKE t527x-orgtx,"Holds the short text for department
      department_no LIKE pernr-orgeh,
      pernr LIKE pernr-pernr,
      ename LIKE pernr-ename,
      grade like t503t-ptext,   "THIS AREA GET ME TEXT OF EMPLOYEE SUBGROUP"
    *  department_text LIKE t527x-orgtx,"Holds the short text for department
      current_year LIKE sy-datum,
      wt0001 LIKE q0008-betrg,"Basic Pay
      wt1101 LIKE q0008-betrg," COLA
      wt3002 LIKE p0015-betrg,"Overtime
      per_basic type p DECIMALS 2,"Overtime percentage on basic
      per_basic_sum type p decimals 2,"Overtime Sum Division
      overtime_sum LIKE p0015-betrg,"holds sum of overtime
      basic_sum like q0008-betrg,"holds sum of basic
    END OF itab_odoe.
    Im using the select statement to get the employee subgroup from the table
    select single ptext
        from t503t
        into itab_odoe-grade
        where persk eq pernr-persk
        AND SPRSL eq 'EN'.
    now in itab_odoe-grade the values comes is Workers (7) , Snr Mgt (M3)
    i want to show only the text in Brackets.

  • I need help regarding measurement of "time domain parameters of Heart rate variability" using labview.

    I need help regarding measurement of "time domain parameters of Heart rate variability" using labview.
    I am using Labview 8 ... I  need to develop a software to accquire the ECG data (simulated enironment ) and compute the time domain parameters of Heart rate variability like "SDNN, SDANN...etc". Can some 1 plllzzzz help me out.Plzz help me if u can.Thanx in advance.

    Hi Andy,
      Thanx for responding.  The input is from a text file. SDNN, SDANN,etc are  the timedomain parameters of heart rate variability.
     SDNN: the standard deviation of the NN or RR interval  i.e. the square root of variance.
    SDANN:the standard deviation of the averageNN interval calculated over short periods, usually 5 min,which is an estimate of the changes in heart rate due tocycles longer than 5 min
    SDNN index, the meanof the 5-min standard deviation of the NN intervalcalculated over 24 h,
     RMSSD: the square root ofthe mean squared differences of successive NN intervals
    NN50: the number of interval differences of successiveNN intervals greater than 50 ms, and
    pNN50 the proportionderived by dividing NN50 by the total numberof NN intervals.
    The problem is dat I am a fresher to the world of Labview. I have jus recently started working on it. Can u please suggest me some some idea as soon as possible.
      As i said  I have the ECG data in the form of text files..I need to create sort of GUI to calculate the time domain parmeters....I need help urgently. Plzzz help me if u can. If u have and .vi example to calculate the RR interval plzz send it to me ASAP.
    Thanku

  • Need Help Regarding Enabling The Matrix

    Hi All,
    We have got one user form and we have got one choose from list and one matrix, on click of choose from list the value will be displayed in the text box and at the same time matrix should get enabled. But it;s not happening in our case. The value is coming in the text box through choose from list but matrix is not getting enabled. We are able to change the back ground color of the matrix, make first column invisible and all but not able to enable the matrix. We need help regarding this one.
    Regards,
    Jayanth

    Hey first bind the columns of matrix to any user datasource
    and then you can enter any thing into your matrix 
    following code may help
    suppose you have one column
    oForm = SBO_Application.Forms.Item("URFRM")
    oUserDataSource = oForm.DataSources.UserDataSources.Add("URDSName",
    SAPbouiCOM.BoDataType.dt_SHORT_TEXT, 20)
    oMatrix=oForm.Item("URMATRX")
    oMatrix = oItem.Specific
    oColumns = oMatrix.Columns
    oColumn = oColumns.Item("URCOLName")
    oColumn.DataBind.SetBound(True, "", "URDSName")
    oMatrix.Addrow()
    hope this will help
    additionally you can look at this sample
    .....SAP\SAP Business One SDK\Samples\COM UI\VB.NET\06.MatrixAndDataSources

  • I need help regarding setting my mail accounts on macbook pro

    I need help regarding resetting my mail accounts on macbook pro

    What kind of accounts do you need to reset? IMAP or POP accounts using one of the many web-based messaging systems? An Exchange server account? Were they working and now just not working any longer?
    You're going to have to be a little more specific in what you need...
    Clinton

  • I need help choosing RAM for MSI PM8PM-V 7222 VER. 2.0 MB

    hey everyone as you know my MB is in the subject and i need help buying ram for it. on the MSI website it says it can surpport max. 2GB so 1GB in each slot? it only has 2 slots also what DDR and MHZ clock, DRAM fequency etc does the ram have to be and both single sided or double sided or 1 single and 1 double?
    thanks

    Quote
    also what DDR and MHZ clock, DRAM fequency etc does the ram have to be
    http://global.msi.eu/index.php?func=proddesc&maincat_no=1&prod_no=1039
    Quote
    • Supports DDR2 533/400 memory interface.
    Check the memory support list for best compatibility:
    http://global.msi.eu/uploads/test_report/TR10_1039.pdf

  • Need Help Regarding  ibook

    em user of   iphone  3gs  os 6.1.6
    Yesterday  i restore ma  iphone
    after that  em  Unable  to   install    ibook in  ma iphone  its  say me that u  need  os 7 ...
    need help regarding this issue....   what i do  is there any alternative app  ...?

    Hey Seungly,
    I've realized that my computer runs fine UNLESS I turn the AirPort on to connect to the Internet. The moment I click "Turn AirPort On," the "You need to restart your computer" screen immediately pops up. Is there any connection between AirPort and my problem?
    That could very easily be the case, a bad Airport card. Look at this recent post:
    http://discussions.apple.com/thread.jspa?messageID=7960754&#7960754
    John diagnosed it from the panic log.
    Does yours say something similar?
    Richard

  • Need help regarding image scanning from scanner and resizing it...

    Hi,
    I need help regarding scanning of image directly from scanner. Here is the scenario when the person clicks scan button on the webpage should scan the image and resize it and store it in some temp location. Is there any way i can do this. Any Help regarding this would be great!!!
    Thanks,
    Avinash.
    Edited by: Kalakonda on Jul 24, 2009 8:08 AM

    Kalakonda wrote:
    I need help regarding scanning of image directly from scanner. Here is the scenario when the person clicks scan button on the webpage should scan the image and resize it and store it in some temp location. Is there any way i can do this. Any Help regarding this would be great!!!So what you are doing is you have a Scanner (hardware: like an HP flatbed scanner) attached to a server that you want to use as a scanning station? Is this the senario that you are talking about?

  • Need help regarding may ipad, i cant access my ipad, need help regarding may ipad, i cant access my ipad

    need help regarding may ipad, i cant access my ipad, need help regarding may ipad, i cant access my ipad

    Can you be little more specific?

  • I need help finding cases for the ipod touch thrid gen help.

    i need help finding case for ipod touch thrid gen help.

    - Try another cable.
    - Try another USB port
    - Inspect the dock connector on the iPod for bent or missing contacts, foreign material, corroded contacts, broken, missing or cracked plastic.
    - Try on another computer. Just backup a couple of times. Do not sync.

Maybe you are looking for

  • Inter-Org Mailbox moves from Exchange 2007 to Exchange 2013

    G'Day All, Is it possible to move Exchange 2007 mailboxes to Exchange 2013 in a different forest? Both environment has all the required patches and service packs. There is a two way trust, and I don't want to introduce Exchange 2010 CAS in the source

  • I lost the output sound on my ibookG4

    So I just installed Leopard on my ibookG4 and now my OUTPUT device for sound is no longer working. when i turn my computer on it makes the normal opening sound, but when i try to listen to itunes or anything that has sound it's dead. i looked at my s

  • HT5625 How to share between iPad and iPhone

    New iPhone 5s. Can I get my apps from my iPad?thanks

  • The invoked JCA adapter raised a resource exception.

    Hello, I have to use an Oracle apps adapter in Bpel. Thus I created a non-XA datasource and a connection pool for the Oracle Apps Adapter - eis/Apps/DS with its datasource as jdbc/DS. Now when I invoke the Oracle apps adapter, i get the following err

  • Cannot sign in to the Apple Store using Apple ID

    I wish to purchase an MBA, and for this purpose I created my first Apple ID. It works absolutely fine on the main Apple site, but it is rejected when attempting to sign in to the Apple Store (it returns the question: have you forgotten your password?