on 03-22-2007 12:02 PM
Hi.
I have the following database table 'testtable':
ID type: serial(1)
name type: varchar(20)
In SQL Studio I have executed the following:
insert into testtable(name) values('blubb')
select testtable.currval from dual
This works exaclty as it should and delivers me the maxdb-generated ID from my newly inserted record.
Strange is that when I do the same with jdbc, I get an exception (executing the select), which contains the message: <i>Unknown sequence name:testtable</i>
I think I am doing something wrong, but I dont have any idea, what it can be. Has anybody similar experiences?
Btw: I have already created a sequence by hand, which was accessible (<sequencename>.currval or <sequencename>.nextval) in sqlstudio. But when doing this with jdbc, I still get the <i>Unknown sequence name:<sequencename></i> error.
Thanks in advance,
Tobias
Hi Tobias,
Yes, MaxDB's JDBC driver is able to handle sequences. I build a small example on this topic:
import java.sql.*;
public class Sequence {
public static void main (String [] args)
throws ClassNotFoundException, SQLException
{
String user = "user";
String password = "pass";
String host = "localhost";
String dbname = "dbname";
/*
* parse arguments
*/
String url = "jdbc:sapdb://" + host + "/" + dbname;
/*
* load driver and connect
*/
Class.forName ("com.sap.dbtech.jdbc.DriverSapDB");
Connection connection = DriverManager.getConnection (url, user, password);
/*
* execute query
*/
Statement stmt = connection.createStatement ();
try {
stmt.executeUpdate("drop table testtable");
} catch (SQLException e) {
// ignore
}
stmt.executeUpdate("Create table testtable (ID serial(1), name varchar(20))");
stmt.executeUpdate("Insert into testtable (name) values('blubb')");
ResultSet rs = stmt.executeQuery("select testtable.currval from dual");
rs.next ();
String hello = rs.getString (1);
System.out.println (hello);
}
}
The example works fine on my environment. I got '1' as result of the query. So if it doesn't work on your environment what is the exact exception (backtrace) that you get. And what is the version of the MaxDB and the JDBC driver (java -jar sapdbc.jar -V) do you use.
regards,
Marco
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
90 | |
10 | |
10 | |
10 | |
7 | |
7 | |
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.