• 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
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

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: 76861
    366
    • 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.
     
    That which doesn't kill us makes us stronger. I think a piece of pie wouldn't kill me. Tiny ad:
    the value of filler advertising in 2021
    https://coderanch.com/t/730886/filler-advertising
    reply
      Bookmark Topic Watch Topic
    • New Topic