Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Can not save boolean in sapdb using jdbc

Hi,

I try to save a boolean in SAPDB by using JDBC but I get a sql error. The error is that I can not save a boolean in to a varchar field. The field type in the table in boolean.

Under you find the source I use.

Richard.

public void createAddress(

int contactId,

int addressId,

boolean show,

String location,

String street,

String postalCode,

String city,

String country,

String user)

throws SQLException {

// TODO Auto-generated method stub

Date date = new Date();

String dateFormat = "yyyy-MM-dd";

String timeFormat = "HH:mm:ss";

SimpleDateFormat ddf = new SimpleDateFormat(dateFormat);

SimpleDateFormat tdf = new SimpleDateFormat(timeFormat);

String creationDate = ddf.format(date);

String creationTime = tdf.format(date);

PreparedStatement newContact =

conn.prepareStatement(

"INSERT INTO BE_ADDRESS (CONTACT_ID, ADDRESS_ID, SHOW, STREET, CITY, ZIPCODE, COUNTRY, DATE_CREATE, TIME_CREATE, USER_CREATE) VALUES (?,?,?,?,?,?,?,?,?,?)");

try {

newContact.setInt(1, contactId);

newContact.setInt(2, addressId);

newContact.setBoolean(3, show);

newContact.setString(11, location);

newContact.setString(4, street);

newContact.setString(5, city);

newContact.setString(6, postalCode);

newContact.setString(7, country);

newContact.setDate(8, java.sql.Date.valueOf(creationDate));

newContact.setTime(9, java.sql.Time.valueOf(creationTime));

newContact.setString(10, user);

newContact.executeUpdate();

} finally {

newContact.close();

}

}

Former Member
Not what you were looking for? View more on this topic or Ask a question