Hi.
I set up a database with 2 users created like this with dbmcli :
sql_execute CREATE USER admin PASSWORD admin RESOURCE
sql_execute CREATE USER toto PASSWORD toto STANDARD
When I execute the attached java program it fails !
The user toto cannot see the table TestGrant created by the user admin.
The GRANT statement does not seem to be executed (returns -1).
I tested to execute the GRANT statement with dbmcli and everything
works.
Am I doing something wrong or is this a bug with the JDBC driver ?
I am using SAP DB 7.3.0.29 on Redhat and the latest JDBC driver
(7.4.04.00d).
Laurent
import java.sql.*;
/**
* Be sure to have a user admin created like this :
* create user admin password admin RESOURCE
* before executing this program.
*/
public class TestGrant {
public static void main(String[] args)
throws SQLException, ClassNotFoundException
{
if (args.length != 2) {
System.err.println("usage: java TestGrant hostname database");
System.exit(1);
}
new TestGrant(args[0], args[1]).run();
}
private TestGrant(String hostname,
String database)
throws SQLException, ClassNotFoundException
{
this.url = "jdbc:sapdb://" + hostname + "/" + database;
Class.forName("com.sap.dbtech.jdbc.DriverSapDB");
}
private void run() throws SQLException {
Connection connection;
Statement select;
ResultSet rset;
boolean created;
// create and fill the table
connection = DriverManager.getConnection(url, "admin", "admin");
select = connection.createStatement();
select.executeUpdate("CREATE TABLE TestGrant (ID INT NOT NULL)");
created = true;
int count = select.executeUpdate("GRANT ALL ON TestGrant TO PUBLIC");
System.err.println("GRANT : " + count);
select.executeUpdate("INSERT INTO TestGrant (ID) VALUES (1)");
select.executeUpdate("INSERT INTO TestGrant (ID) VALUES (2)");
connection.commit();
connection.close();
try {
try {
// try to get values from the table
connection = DriverManager.getConnection(url, "toto", "toto");
select = connection.createStatement();
select.setCursorName("mycursor");
rset = select.executeQuery("SELECT ID FROM TestGrant");
while (rset.next()) {
System.out.println("id :" + rset.getInt("ID"));
}
rset.close();
connection.close();
} finally {
connection.close();
}
} finally {
if (created) {
// drop the table
connection = DriverManager.getConnection(url, "admin", "admin");
select = connection.createStatement();
select.executeUpdate("DROP TABLE TestGrant");
connection.close();
}
}
}
// ----------------------------------------------------------------------
private final String url;
}