• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Errors ";" and "may not have been initialized" on my project that I can't solve?

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello, I am getting errors in my code (lines 26, 29 34) for ";" expected on String sql "INSERT INTO Customer VALUES ('"+ customer.getCustomerID() +"', '"+ customer.getFirstName() +"'," and "variable sql may not have been initialized on line [i]executeModifyQuery(sql); I have been adding and subtracting ";" everywhere but I just don't get it? I also don't get the other error as it is written 2 other times and is not returning an error? Any help for a new guy would be great. Thanks!

-M

[/i]
 
Ranch Hand
Posts: 624
9
BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

M Sparks wrote:


You have missed the assignment operator (=).
String sql = "INSET INTO....
String sql = "UPDATE...
 
Tapas Chand
Ranch Hand
Posts: 624
9
BSD Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Few more things to remember.

1. It is better to use java.sql.PreparedStatement instead of java.sql.Statement.
  • It helps avoiding SQL Injection.
  • It makes your code more readable.
  • It is pre-compiled, so faster in case of executing same query multiple times with different parameters.

  • 2. It is better to release SQL objects in finally block instead of try block.
    Imagine a case when you got a Connection object and exception occurs before releasing it.
    Then after some time you will get "Maximum connections exceeded" or "Maximum open cursors exceeded" errors.
     
    M Sparks
    Greenhorn
    Posts: 13
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Awesome, can't believe I missed that! Also, I have already changed to PreparedStatement, that is way better. Thanks for your help!

    -M
     
    M Sparks
    Greenhorn
    Posts: 13
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    I have a MySQL database I am connected to in NetBeans called "IT351". Any chance anyone could point me to a "how to" or explain briefly how to take all the data typed in the GUI and store in said MySQL database (IT351)? Then I how I would check to see the data in the database on NetBeans. Thanks.
     
    Tapas Chand
    Ranch Hand
    Posts: 624
    9
    BSD Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    M Sparks wrote:I have a MySQL database I am connected to in NetBeans called "IT351". Any chance anyone could point me to a "how to" or explain briefly how to take all the data typed in the GUI and store in said MySQL database (IT351)? Then I how I would check to see the data in the database on NetBeans. Thanks.


    I have never used Netbeans, but as far as database is concerned, I always prefer database tools to manage them instead of Java IDE, MySQL Workbench for MySQL as an example.
     
    Marshal
    Posts: 79275
    377
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Another reason why you couldn't find the compiler error may be that you are writing too much code at once. Write not more than five lines of code, compile and run it and check for errors. Then write the next five lines.
     
    Don't get me started about those stupid light bulbs.
    reply
      Bookmark Topic Watch Topic
    • New Topic