Connecting a GUI to a Derby Database with NetBeans

Hello, I did the tutorial, Connecting a GUI to a Derby Database. At:

http://www.netbeans.org/kb/50/gui-database.html

but I am getting the following error:

JdbcRowSet (setTypeMap): Connection.setTypeMap is not supported

Since I am pretty new to Java and NeyBeans, it is probably something pretty basic, that is causing the error.

Thanks for your help.

ps: one other thing I am trying to figure out is how to have a different look and feel after complile. It has kind of a Windows 3.1 look. I was hoping to have a nicer look that would be consistent across all platforms.

[615 byte] By [gloria@homea] at [2007-10-3 5:20:14]
# 1

> Hello, I did the tutorial, Connecting a GUI to a

> Derby Database. At:

> http://www.netbeans.org/kb/50/gui-database.html

> but I am getting the following error:

> JdbcRowSet (setTypeMap): Connection.setTypeMap is not

> supported

>

> Since I am pretty new to Java and NeyBeans, it is

> probably something pretty basic, that is causing the

> error.

If it isn't supported it isn't supported. Not all of the latest (or otherwise) JDBC features etc are supported by all drivers/databases.

Apparently your driver does not support the setTypeMap feature. To be honest this is not a feature I have seen a great deal of usage of so hopefully and probably it won't actually be critical to your usage.

>

> Thanks for your help.

>

> ps: one other thing I am trying to figure out is how

> to have a different look and feel after complile. It

> has kind of a Windows 3.1 look. I was hoping to have

> a nicer look that would be consistent across all

> platforms.

This question belongs in the Swing forum but more information will be required. You should post some formatted code explaining what GUI widgets you are using (AWT, Swing, other) and some explanation of what you have tried to this point.

If you are using Swing you can change the look and feel pretty easily but I don't know if this answers your question.

http://java.sun.com/docs/books/tutorial/uiswing/misc/plaf.html

cotton.ma at 2007-7-14 23:27:09 > top of Java-index,Java Essentials,Java Programming...
# 2
Thanks for your reply, I found this site by doing a google search. I now see, and should have known that there were more specific areas for questions. I should post my basic questions to New To Java, Swing, JDBC, forums etc.
gloria@homea at 2007-7-14 23:27:09 > top of Java-index,Java Essentials,Java Programming...
# 3

> Thanks for your reply, I found this site by doing a

> google search. I now see, and should have known that

> there were more specific areas for questions. I

> should post my basic questions to New To Java, Swing,

> JDBC, forums etc.

Do you understand what I posted about not implemented though?

cotton.ma at 2007-7-14 23:27:09 > top of Java-index,Java Essentials,Java Programming...
# 4

No apparently you didn't.

Gloria,

I am glad that for future questions you understand that you should post in the appropriate forum but there is no need to post this question in other forums. I already answered it.

No matter how many forums you post into the answer about setTypeMap will be the same. It isn't implemented by your driver and that's the end of it.

cotton.ma at 2007-7-14 23:27:09 > top of Java-index,Java Essentials,Java Programming...
# 5
Yes, I think I understand. But NetBeans is a Sun Product and Derby (Java DB) is now a Sun Product, and the tutorial at http://www.netbeans.org/kb/50/gui-database.html was created by Sun, so I thought it must somehow work, and that I am doing somthing wrong.Thanks again.
gloria@homea at 2007-7-14 23:27:09 > top of Java-index,Java Essentials,Java Programming...
# 6

> Yes, I think I understand. But NetBeans is a Sun

> Product and Derby (Java DB) is now a Sun Product, and

> the tutorial at

> http://www.netbeans.org/kb/50/gui-database.html

> was created by Sun, so I thought it must somehow

> work, and that I am doing somthing wrong.

>

Well I can see where you would draw that reasonable conclusion. However I can assure you that you are not doing something wrong if you are following the tutorial in terms of code correctly.

Unfortunatley Sun is not as competent as one might hope.

I suspect that either the tutorial was always wrong or more likely it worked with a different version of Derby or the JDBC driver than the one you are using. You might check to see if there is a newer version of the JDBC driver you are using.

But you haven't done anything wrong per se.

cotton.ma at 2007-7-14 23:27:09 > top of Java-index,Java Essentials,Java Programming...
# 7
jnull
ggopia at 2007-7-14 23:27:09 > top of Java-index,Java Essentials,Java Programming...
# 8

Hello again, you were right about that error having to do with Derby (Java DB), because when I connected to a PostgreSQL database, the error went away. But now I have a different error that appears when NetBeans tries to insert a record.

-

insert into contacts(id, first_name, last_name)

org.postgresql.util.PSQLException: ERROR: relation "contacts" does not exist

-

I think PostgreSQL needs a SQL statement to formatted like the following: "schema"."tablename"

To include parenthesis around the schema name followed by a dot, followed by the table name. But in the insert statement that NetBeans is creating, just includes the the table name. I have tried to modify the code in different ways, but I can't get it to format the SQL statement correctly.

I have included the entire statement below. Thanks again for any help.

/**

* Updates the selected contact or inserts a new one (if we are

* in the insert mode).

*

* @param firstName first name of the contact.

* @param lastName last name of the contact.

* @param title title of the contact.

* @param nickname nickname of the contact.

* @param displayFormat display format for the contact.

* @param mailFormat mail format for the contact.

* @param emails email addresses of the contact.

*/

public void updateContact(String firstName, String lastName, String title, String nickname,

int displayFormat, int mailFormat, Object[] emails) {

int selection = getContactSelection().getMinSelectionIndex();

Statement stmt = null;

try {

if (!insertMode) {

rowSet.absolute(selection+1);

}

Connection con = rowSet.getConnection();

stmt = con.createStatement();

String sql;

if (insertMode) {

sql = "insert into public." + CONTACTS_TABLE + "(" + CONTACTS_KEY + ", " + CONTACTS_FIRST_NAME + ", "

+ CONTACTS_LAST_NAME + ", " + CONTACTS_TITLE + ", " + CONTACTS_NICKNAME + ", "

+ CONTACTS_DISPLAY_FORMAT + ", " + CONTACTS_MAIL_FORMAT + ", " + CONTACTS_EMAIL_ADDRESSES

+ ") values ((case when (select max(" + CONTACTS_KEY + ") from " + CONTACTS_TABLE + ")"

+ "IS NULL then 1 else (select max(" + CONTACTS_KEY + ") from " + CONTACTS_TABLE + ")+1 end), "

+ encodeSQL(firstName) + ", " + encodeSQL(lastName) + ", " + encodeSQL(title) + ", "

+ encodeSQL(nickname) + ", " + displayFormat + ", " + mailFormat + ", "

+ encodeSQL(encodeEmails(emails)) + ")";

} else {

sql = "update public." + CONTACTS_TABLE + " set ";

sql += CONTACTS_FIRST_NAME + '=' + encodeSQL(firstName) + ", ";

sql += CONTACTS_LAST_NAME + '=' + encodeSQL(lastName) + ", ";

sql += CONTACTS_TITLE + '=' + encodeSQL(title) + ", ";

sql += CONTACTS_NICKNAME + '=' + encodeSQL(nickname) + ", ";

sql += CONTACTS_DISPLAY_FORMAT + '=' + displayFormat + ", ";

sql += CONTACTS_MAIL_FORMAT + '=' + mailFormat + ", ";

sql += CONTACTS_EMAIL_ADDRESSES + '=' + encodeSQL(encodeEmails(emails));

sql += " where " + CONTACTS_KEY + '=' + rowSet.getObject(CONTACTS_KEY);

}

System.out.println(sql);

stmt.executeUpdate(sql);

rowSet.execute();

} catch (SQLException sqlex) {

sqlex.printStackTrace();

} finally {

setInsertMode(false);

if (stmt != null) {

try {

stmt.close();

} catch (SQLException sqlex) {

sqlex.printStackTrace();

}

}

}

}

gloria@homea at 2007-7-14 23:27:09 > top of Java-index,Java Essentials,Java Programming...