cancel
Showing results for 
Search instead for 
Did you mean: 

CREATE TABLE with boolean column in MaxDB via Java interface

Former Member
0 Kudos

I am writing a Java application against MaxDB Version Version: 7.7.04.28. Apparently it is difficult to create a table with a boolean column in Java code.

It seems that MaxDB supports the boolean datatype but the Java interface does not support it. Is this a known problem? Is there a known solution?

The SQL code I want to run is similar to this simplified example:

CREATE TABLE WEBUSERS ("ID" INTEGER NOT NULL, "NAME" CHAR (120) UNICODE, "READACCESS" BOOLEAN, "WRITEACCESS" BOOLEAN)

I can run this code through the SQL command line interface and it works fine. I can also create the table manually in Database Studio and look at the generated code in the console window and again it is fine.

However, the Java code below gives this error message: [-3002] (at 81): Invalid datatype

It is also possible to construct a java.sql.DatabaseMetaData object and infer the available data types from MaxDB. Again I do not see a Boolean or anything equivalent like BIT.

Thanks for any response

CODE SAMPLE

This works if you omit the boolean columns.

public static void main(String[] args)

{

String commandText = "CREATE TABLE WEBUSERS (\"ID\" INTEGER NOT NULL, \"NAME\" CHAR (120) UNICODE, \"READACCESS\" BOOLEAN, \"WRITEACCESS\" BOOLEAN)";

try

{

//

//Opening a connection:

//

String jdbcDriver = "com.sap.dbtech.jdbc.DriverSapDB";

//MYMOUSER is created as a 'Resource'

String connectionUrl = "jdbc:sapdb://localhost/MYDATABASE?sqlmode=ORACLE&user=MYUSER&password=MYPASSWORD";

Class.forName(jdbcDriver);

Connection cn = DriverManager.getConnection(connectionUrl);

//

//Creating a table:

//

Statement createStatement = cn.createStatement();

boolean result = createStatement.execute(commandText);

//

//Closing the connection (this should be in a finally block):

//

cn.close();

}

catch (Exception exc)

{

System.out.println(exc.getMessage());

}

}

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Great! This solves the problem.

We were trying to find other options for the sqlmode but it seemed to us that there was only ORACLE. We did not know about INTERNAL.

Thankss!

lbreddemann
Active Contributor
0 Kudos

That's an easy one (I guess..)

String connectionUrl = "jdbc:sapdb://localhost/MYDATABASE?sqlmode=ORACLE&user=MYUSER&password=MYPASSWORD";
                                                                  ^^^^^^

Oracle does not know a BOOLEAN data type.

Use the sqlmode INTERNAL instead and this should work.

regards,

Lars