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