Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Databases / October 2005

Tip: Looking for answers? Try searching our database.

Help with SQL - Variable Not Initialized?

Thread view: 
GRoll21 - 18 Oct 2005 18:01 GMT
Here is my code. It is an update of another program. For some reason
says my jcd_id cannot be initialized. Here is the error   -

"c:\Java\oraclePgms>javac update.java
update.java:81: Variable jcd_id may not have been initialized.
  _sJT_st.setInt(1, jcd_id);

Any suggestions would be great! Thanks!

import java.sql.*;
import oracle.sqlj.runtime.Oracle;

public class update
{

    public static void main (String[] args)
    {

        int jcd_id, jidp;
        String jcd_author, jcd_title, jcd_genre;
        double jcd_cost, jcd_retail;

    try
    {

Oracle.connect("jdbc:oracle:thin:@localhost:1521:orcl","DBUSER","oracle");

        #sql
        {
            UPDATE
                javausermar
            SET
                o_cost = ocost * 1.05

        };
            System.out.println("Cost: " +jcd_cost);

        //////////////////////////////////////display
record//////////////////////////////////////

        #sql
        {
            SELECT
                o_author, o_title, o_genre, o_cost, o_retail
            INTO

                :jcd_author, :jcd_title, :jcd_genre, :jcd_cost, :jcd_retail

            FROM
                javaUserMAR
            WHERE
                o_id = :jcd_id

        };

    }

        catch (SQLException e)
        {
            System.err.println("SQLException " + e);
        }

        catch (Exception e)
            {
            }

        finally
        {
            try
            {
                Oracle.close();
            }

            catch (SQLException e)
            {
                System.err.println("SQLException " + e);
            }
       
       
        }
    }

}
Bjorn Abelli - 18 Oct 2005 23:37 GMT
"GRoll21" wrote...

As noone else yet has tried to answer this, I'll give it a shot...

> Here is my code. It is an update of another program.
> For some reason says my jcd_id cannot be initialized.

I'm not that familiar with SQLJ (which I guess this is), but from what I
see, I'm more surprised that the compiler doesn't scream even before that
line.

> "c:\Java\oraclePgms>javac update.java
> update.java:81: Variable jcd_id may not have been initialized.
>   _sJT_st.setInt(1, jcd_id);
>
> Any suggestions would be great! Thanks!

If we look at the actual message, it's quite clear that "jcd_id" hasn't been
initialized!

Instance variables are "automatically" initialized with default values.

Local variables are *not*.

So, let's see where you put a value into "jcd_id" before you use it...

And in the code you provided... Nowhere!

Actually, I would have expected the compiler to give you a similar message
on "jcd_cost" as well, which you use in this line...

> System.out.println("Cost: " + jcd_cost);

...without having it initialized anywhere.

// Bjorn A


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.