aspose file tools*
The moose likes JDBC and the fly likes inserting a integer value to oracle Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "inserting a integer value to oracle" Watch "inserting a integer value to oracle" New topic
Author

inserting a integer value to oracle

Megha Rajeevan
Greenhorn

Joined: Mar 22, 2006
Posts: 24
Hello Ranchers
how to insert a integer value which is in sequence
please help me

the query i'm using is

=========================================================================

String query = "insert into test(id,name,sex)values(s_id.nextval,?,?))";

PreparedStatement ps = dbCon.prepareStatement(query);
ps.setInt(1,id);
ps.setString(2,name);
ps.setString(3,sex);

=========================================================================

but what if i'm inserting a string value in a sequence.. then i just want to give ps.setString(1,"");
it will insert
but now i want to give the integer value
so which one i can use..
please help me ranchers..

thanks in advance..
regards
Megha!!
stu derby
Ranch Hand

Joined: Dec 15, 2005
Posts: 333
No, no, no. The SQL generates and inserts the value for you; you don't have to supply and bind a value to your PreparedStatement


[ May 26, 2006: Message edited by: stu derby ]
Megha Rajeevan
Greenhorn

Joined: Mar 22, 2006
Posts: 24
Thank you ranchers..
this query is working fine..
but there is a problem also..
if i want to get the current value of the sequence.. what to do

i've done like this


String query = "select system.login_id.currval from dual";
ResultSet rs = stmt.executeQuery(query);
while(rs.next())
{int id_val = rs.getInt(1);
}


i don't kjnow whether it is true..
just put a trial..
but it is showing the error..

java.sql.SQLException: [Oracle][ODBC][Ora]ORA-08002: sequence LOGIN_ID.CURRVAL is not yet defined in this session


but if i'm giving the nextval.. it is working fine..
how to fix this problem..
please help me ranchers..

thanks in advance

regards
Megha
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: inserting a integer value to oracle