Why cant i do this?

Hi,
I tried doing this but it's not allowed.
String     HOST = "jdbc:odbc:LogAccess",
             DRIVER = "sun.jdbc.odbc.JdbcOdbcDriver";
     try {
          // connect to db
          Class.forName(DRIVER).newInstance();
          Connection con = DriverManager.getConnection(HOST,"","");
          PreparedStatement ps = null;
          if(TABLE_NAME.endsWith("2002")){
          String query = "INSERT INTO WebLog2002 VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?)";
          }else{
          String query = "INSERT INTO WebLog2001 VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?)";
          ps = con.prepareStatement(query);
          int count=0;
          while(count<=totalRows) {The error is
C:\newclasses\logger3.java:174: cannot resolve symbol
symbol : variable query
location: class logger3
          ps = con.prepareStatement(query);
^
1 error
Tool completed with exit code 1
Why is that so?
Please advise...thanks....

A: Why cant i do this?

Declare query before you enter the if statement.
String query = null;
if (condition) {
  query = ...
} else {
  query = ...
}or use the ? : syntax
String query = TABLE_NAME.endsWith("2002") ?
  "INSERT INTO WebLog2002 VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?)" :
  "INSERT INTO WebLog2001 VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?)"If TABLE_NAME is WebLog2002 or WebLog2001, you can do it as:
String query = "INSERT INTO "+TABLE_NAME+" VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?)";

Declare query before you enter the if statement.
String query = null;
if (condition) {
  query = ...
} else {
  query = ...
}or use the ? : syntax
String query = TABLE_NAME.endsWith("2002") ?
  "INSERT INTO WebLog2002 VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?)" :
  "INSERT INTO WebLog2001 VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?)"If TABLE_NAME is WebLog2002 or WebLog2001, you can do it as:
String query = "INSERT INTO "+TABLE_NAME+" VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?)";

Similar Messages

  • I can only scroll using the arrow keys. In IE/C I can use the touch pad to slide my fingers to scroll. Why cant i do this in FF?!?!

    On my laptop (and most for that matter) you can use the touch pad to slide your fingers to scroll thru a web page. I cannot do this in firefox. It is very annoying and I dont know why cant do this?
    I have reinstalled FF and it still wont scroll! Every other browser i can scroll thru a web page using the touch pad method.
    Why cant i do this on FF?

    Hello and Welcome to Apple Discussions!
    Full keyboard access is useful for people who have difficulty using a mouse. Safari supports standard full keyboard access shortcuts for buttons and menus. If you choose, you can also use the keyboard to highlight links in webpages.
    To turn on full keyboard access:
    Choose Apple menu > System Preferences and click Keyboard & Mouse.
    Click Keyboard Shortcuts.
    Select the checkbox to turn on full keyboard access.
    To highlight links in webpages using the Tab key:
    Choose Safari > Preferences and click Advanced.
    Select the option to highlight each item on the web page using the Tab key.
    With full keyboard access turned on, Safari uses the standard shortcut keys to access menus and windows, plus the additional shortcuts shown in the table.
    Hope this helps!!
    Carolyn

  • Why cant i send this to the cost class on button click?

    when the calculate button is clicked i want the program to check and see if a certain checkbox is selected and if set a variable in another class.
    in the code below. why does it not recognize that i am trying to send the variable from the checkbox to the set method in the cost class?
    public class ButtonHandler implements ActionListener{
              public void actionPerformed(ActionEvent ae){
                   if(ae.getSource()==jbnCalculate)
                        String f = jtfFirst.getText();
                        String l = jtfLast.getText();
                        String id = jtfID.getText();
                        if(cbCream.isSelected()){
                             app1.setCream(ch);
    package final_Kelm;
    public class GMCCost extends GMCEmployee {
         double white;
         double wheat ;
         double creamCheese;
         double butter;
         double peachJelly;
         double blueberryJam;
         //double regularCoffee = 1.25;
         //double mocha = 2.75;
         //double latte = 3.05;
         double coffee;
         double total, subTotal;
         double TAX_RATE = 0.0825;
         public GMCCost()
              total = 0.0;
              subTotal = 0.0;
         public void setCoffee(double c)
              if(c==1)
                   coffee = 1.25;
              else if(c==2)
                   coffee = 2.75;
              else if(c==3)
                   coffee = 3.05;
              else
                   coffee = 0.0;
         public double getCoffee()
              return coffee;
         public void setCream(double ch)
              ch = 0.5;
              ch = creamCheese;
         public double getCream()
              return creamCheese;
         }i am having the same trouble with the coffee. i cannot add it to the output by "Coffee Price: " + app1.getCoffee() + . . . . .

    why is this considered wrong or bad . . .
    public class ButtonHandler implements ActionListener{
              public void actionPerformed(ActionEvent ae){
                   if(ae.getSource()==jbnCalculate)
                        double butter, peach, blueberry, white, wheat;
                        double creamCheese, subTotal, total;
                        String f = jtfFirst.getText();
                        String l = jtfLast.getText();
                        String id = jtfID.getText();
                        double TAX_RATE = 0.0825;
                        if(cbCream.isSelected()){
                             creamCheese = 0.5;
                        else{
                             creamCheese = 0.0;
                        if(cbButter.isSelected()){
                             butter = 0.25;
                        else {
                             butter = 0.0;
                        if(cbPeach.isSelected()) {
                             peach = 0.75;
                        else {
                             peach = 0.0;
                        if(cbBlueberry.isSelected()) {
                             blueberry = 0.75;
                        else {
                             blueberry = 0.0;
                        if(jrbWhite.isSelected()) {
                             white = 1.25;
                        else{
                             white = 0.0;
                        if(jrbWheat.isSelected()) {
                             wheat = 1.50;
                        else {
                             wheat = 0.0;
                        double coffee = jcbCoffee.getSelectedIndex();
                        if(coffee==0) {
                             coffee = 0.0;
                        else if(coffee==1) {
                             coffee = 1.25;
                        else if(coffee==2) {
                             coffee = 2.75;
                        else {
                             coffee = 3.05;
                        subTotal = white + wheat + creamCheese + butter + peach + blueberry + coffee;
                        total = subTotal + (subTotal * TAX_RATE);
                        jtaOutput.setText("");
                        output = output+ "Employee Information: " +"\nStaff ID: " + id + "\nStaff First Name: " + f + "\nStaff Last Name: " + l +
                        "\nInvoice: " + "\nSubtotal: " + subTotal + "\nTotal: " + total;
                   jtaOutput.append(output);
                   }as compared to the code i first posted . . . . . this code works . . . the gui works . . . and im assuming this class of code can run all by itself and does have or need anything to do with the other 3 classes are in this program (see previous thread).
    this program works but all the code is in the button handler class . . . i do not need to send anything anywhere, i do not need to use set get methods . . . so why would this code be frowned upon?

  • How do i automate volume on an audio track??? why cant i figure this out.

    in logic 8 i cant figure out how to automate volume for an audio track. With midi its fine i just use the hyper editor but with audio i just cant get it figured out. I want to mute the portions of a vocal track where there are no vocals.

    Go to your key commands window and find out how
    to view volume automation.
    Then press that button and automate away.

  • Why cant I solve this one? "download error tap to retry"

    I've got a new iPhone 5 and I have bought four tracks from iTunes to get going with (I usually use Spotify but I want these tracks for ringtones) I can download the tracks on my laptop (which runs windows 7) and on my iPad (4th generation) but on the phone, the same message comes up again and again. I've tried restarting the phone, resetting the network settings, resetting all settings, restoring the phone on iTunes. Nothing works. The phone syncs with the laptop in iTunes, everything except the music. I've got music ticked in the options and I have the option selected to transfer entire music library (which is only 38 songs). In the drop down menu on the left, the phone shows all the music under the "music" tab, but only in grey and you cannot open or play any of it from there, although you can play any of the tunes if you access them from the iTunes menu at the top left. I'm going mad, here. Apple are running out of answers. Can anyone help?

    Are you using a PC or a Mac? Have you tried to reset your sync history? You say that you tried a restore, was that a restore from a backup, or a restore as a new device? Have you tried unselecting music to sync, sync the device and then select music again and then try to sync the device?

  • I have $10.27 on my account but i cant by a album that is $9.99 why cant i buy it

    why cant i buy this album it is olny $9.99 and i have $10.27 on my account

    If you are in the US then there may be tax to pay on top of the $9.99 which takes it over your $10.27

  • Have a look see what you can do .why cant anyone help with this is it that complicated?

    HERE IS WHAT I HAVE DONE.
    All i am trying to do is insert a simple piece of audio what
    am I doing wrong. Is it my browser pluginfolder? I dont think so
    because flash shockwave mp3 mp4 midi wave avi mpeg wma quicktime
    realtime everthing plays outside dreamweaver is it dreamweaver
    plugins? I have downloaded flash and shockwave from this site via
    manually install plugins from websit preview in design view. Is it
    that my folders are just not configured correctly? Why do i get
    these errors please please please help some one has to know...
    here is what i have being doing .
    1. Made a folder and called it webwork.
    2 Made a folder and called it imagies
    3 made a folder and called it media. I have put the media
    folder in the imagies folder the imagies folder in the web folder
    so Im left with one main folder.
    4 I have defined dreamweaver site as follows. local
    rootfolder (webwork) c/documentsandsettings/myusername/webwork
    default imagies folder
    c/documentsandsettings/myusername/webwork/imagies
    5 on starting a web page I call it my webwork1.html and save
    it.
    6 I import a converted media file from flash encoder put it
    in the media folder along with an none converted media file just to
    see .
    7 I goto insert media shockwave or insert plugin or insert
    flash( look in webwork imagies media select the file (my tune)
    8 When I try to play this in design view i get the error
    message (unable to find media that handles this media type
    dreamweaver looks in both the configuration/plugins folder and the
    plugin folders of each of your web browsers)so i copy my web
    browser plugin folder and put it in my webwork media folder still
    nothing
    9 When I view it on my browser the media icon(shockwave)
    disapears and the puzzel icon appears (plugin) when i click the
    plugin no plugins are found
    10 When i do this process through flash button paper or text
    and load it up to my web browser it downloads the tune and plays
    away via my plugin winamp5?
    11 All I want to do is to emmbed a tune so you have the
    option of playing it stopping it (but not downloading it to listen
    to) why cant this work for me? Is there a fault with the browser or
    dw8 or me.
    system windows 2000xp
    browser firefox 1.5 plugins all
    PLEASE HELP I HAVE TRIED ALL FOR TWO WEEKS
    for one on one and 10mins of
    your time please mail me

    Connect the iPod to your computer and restore via iTunes
    iTunes: Restoring iOS software

  • Why cant I open a PDF file from a cd-r that I burned into this cd myself at work on my personal laptop? I have the same version of Adobe.

    Why cant I open a PDF file from a cd-r that I burned into this cd myself at work on my personal laptop? I have the same version of Adobe.

    What happens when you try? Have you saved to your computer and then tried to open it?

  • Why cant i download from itunes to my mac  error message keeps telling is i dont ave write access? how can i can this?

    why cant i download from itunes to my mac  eror message keeps telling is i dont ave write access? how can i can this?

    Apparently cookies was turned off in Safari. I rarely use it so I have no idea how that happened. Anyway, turning them on seems to have cured the problem.

  • HT4623 why cant i save phone image to photo album...its show save this image to your phone app?,,,,,but no image is save

    why cant i save phone image to photo album...its show save this image to your phone app?,,,,,but no image is save

    Hi FANMixco,
    To be clear, you can see the image from your file system but cannot access it from code?
    I'd like to know what could be my bug because I don't understand why I can access from the URL,
    -> If you can access the image from URL, you should definitely download it and use it, I'm not quite understand your question now.
    I'm not knowledgeable with chmod under Linux, let's say if we give it full accessibility, what will be the result?
    Anyway if you can see the image from file system, that already means the upload is succeed, I think you may need get some suggestion from php side to see how can we save the image with a correct permission.
    I will move the question to off topic, since the question is on the server side but not client side, which is out of the forum support scope, thanks for your understanding.
    --James
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • I cant copy and paste images with firefox but i can with MS explorer why and how is this?

    i cant copy and paste images with firefox but i can with MS explorer why and how is this? i can only copy text but not images is ther a way i can copy images with firefox and how??

    I was having this issue with MS Live email. The old Microsoft shortcuts work. For copy press ctrl+c. For paste press ctrl+v. Here is a webpage that lists all Firefox shortcuts. http://www.mouserunner.com/FF_Shortcuts1Printable.html

  • Why cant I have the date format like this:  1/2/07, it converts to Jan 2

    Why cant I have the date format like this: 1/2/07, it converts to Jan 2, 2007
    I want to keep it like that because, I transported a huge spreadsheet from my PC, and it has like this: 1/1/07, and there is way to many, to go back and change. Please help. Thank you.

    Hello
    Welcome to the club.
    The response seems to be simple.
    Those who wrote the Help are not those who wrote the PDF User's Guide which are not those who coded the application.
    As on this forum you will met only users trying to help other users, no one would be able to tell you if what we got is a bug or a design flaw.
    Like many of us,
    *Go to "Provide Numbers Feedback" in the "Numbers" menu*, describe what you wish: a way to define the default format used as Automatic date/time.
    Then, cross your fingers, and wait for iWork'09
    Yvan KOENIG (from FRANCE mardi 15 janvier 2008 15:10:17)

  • Why cant i sync my devices with this new version of iTunes? my devices are suddenly not being recognized.

    why cant i sync my devices with this new version of iTunes? my devices are suddenly not being recognized. HELP!

    Connect your iPod, iPhone, or iPad to your computer and select your device.

  • TS3988 please help i upgraded my iphone5 to new ios7 yesterday 2pm and untill now its already 17hours and why cant access or back to normal?is this normal or stil upgrading? it only appears the apple logo on screen and keep coming the logo screen on and o

    please help i upgraded my iphone5 to new ios7 yesterday 2pm and untill now its already 17hours and why cant access or back to normal?is this normal or stil upgrading? it only appears the apple logo on screen and keep coming the logo screen on and off.do i need to bring my phone to apple center or is this iops 7 takes longer time or an hours to successfully upgraded.please help me what can i do?

    Anyone have any suggestions? or is everyone else just as clueless as me !

  • HT3939 why cant i update my ios 4.2.1 to 4.3 on my iphone 3g? is there any possible way to do this?

    why cant i update my ios 4.2.1 to 4.3 on my iphone 3g? is there any possible way to do this?

    Because the iPhone 3G isn't capable of running iOS 4.3 or newer.
    (76029)

Maybe you are looking for