File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

inserting a integer value to oracle

 
Megha Rajeevan
Greenhorn
Posts: 24
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 333
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 24
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic