on 09-06-2007 5:53 AM
Hi
I have a table in MAXDB which uses a Sequence to generate
unique nos for the records.
CREATE SEQUENCE Z_DOCU_EXCHANGE_SEQ
START WITH 1
INCREMENT BY 1
When i run a insert statement through SQL Studio the record gets inserted properly.
INSERT INTO Z_DOCU_EXCHANGE VALUES(Z_DOCU_EXCHANGE_SEQ.NEXTVAL,
'A','B','C')
when i try the same through WebDynpro the record does not get inserted.
i am using the following String
String strInsert="INSERT INTO Z_DOCU_EXCHANGE VALUES(Z_DOCU_EXCHANGE_SEQ.NEXTVAL,'A','B','C')";
Is there any special syntax to use MAXDB Sequence in SQL Statement
through WebDynpro ?
Regards
Rajendra
Hi RajendraKumar,
Try using this:
java.sql.PreparedStatement ps =
//Here con is your connection object.
con.prepareStatement("insert into Z_DOCU_EXCHANGE VALUES " +
"(<field1>, <field2>, <field3>, <field4>) " +
"values (?, ?, ?, ?)");
try {
ps.setInt (1, Z_DOCU_EXCHANGE_SEQ.NEXTVAL);
ps.setString(2, "A");
ps.setString(3, "B");
ps.setString(4, "C");
ps.executeUpdate();
} finally {
ps.close();
}
Regards,
Murtuza
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi All ,
The Problem was that the Sequence had to be executed on MAXDB
and i was trying to pass it as Query Parameter , which WebDynpro had no
idea.
The Problem was solved by using Stored procedure and
calling the sequence inside the same.
Thanks for your Suggesstions.
Regards
Rajendra
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi
Do this
String x=Integer.toString(Z_DOCU_EXCHANGE_SEQ.NEXTVAL);
ps.setInt (1, Integer.parseInt(x));
Regards
Abhijith YS
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi
you can convert it into int using
Integer.parseInt(Z_DOCU_EXCHANGE_SEQ.NEXTVAL ) if its a String
what is the return type of Z_DOCU_EXCHANGE_SEQ.NEXTVAL
Regards
Abhijith YS
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi please find little correction with the above code
java.sql.PreparedStatement ps =
//Here con is your connection object.
try {
con.prepareStatement("insert into Z_DOCU_EXCHANGE VALUES " +
"(<field1>, <field2>, <field3>, <field4>) " +
"values (?, ?, ?, ?)");
ps.setInt (1, Z_DOCU_EXCHANGE_SEQ.NEXTVAL);
ps.setString(2, "A");
ps.setString(3, "B");
ps.setString(4, "C");
ps.executeUpdate();
}catch(SqlException sql){}
catch(Exception ex){}
finally {
try{
ps.close();
}
catch(Exception e){}
}
Regards
Abhijith YS
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
87 | |
10 | |
10 | |
9 | |
7 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.