Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reaction of Jaybird when the parameter charSet UTF8 is used [JDBC101] #140

Closed
firebird-automations opened this issue Aug 21, 2007 · 4 comments

Comments

@firebird-automations
Copy link

Submitted by: Andreas Rulle (paderepiktet)

Assigned to: Roman Rokytskyy (rrokytskyy)

When a connection is requested via

Properties props = new Properties();
props.put("user", "sysdba");
props.put ("password", "masterkey");
props.put ("charSet", "UTF8");
c = java.sql.DriverManager.getConnection(databaseURL, props);

the following exception is thrown:

org.firebirdsql.jdbc.FBSQLException: GDS Exception. 335544382. Invalid clumplet buffer structure: buffer end before end of clumplet - clumplet too long
Reason: Invalid clumplet buffer structure: buffer end before end of clumplet - clumplet too long
at org.firebirdsql.jdbc.FBDataSource.getConnection(FBDataSource.java:122)
at org.firebirdsql.jdbc.FBDriver.connect(FBDriver.java:131)
at java.sql.DriverManager.getConnection(DriverManager.java:525)
at java.sql.DriverManager.getConnection(DriverManager.java:140)
at de.intermoves.eubicon.TestCharSet.main(TestCharSet.java:67)
at org.firebirdsql.gds.GDSException: Invalid clumplet buffer structure: buffer end before end of clumplet - clumplet too long
at org.firebirdsql.gds.impl.wire.AbstractJavaGDSImpl.readStatusVector(AbstractJavaGDSImpl.java:2124)
at org.firebirdsql.gds.impl.wire.AbstractJavaGDSImpl.receiveResponse(AbstractJavaGDSImpl.java:2074)
at org.firebirdsql.gds.impl.wire.AbstractJavaGDSImpl.internalAttachDatabase(AbstractJavaGDSImpl.java:414)
at org.firebirdsql.gds.impl.wire.AbstractJavaGDSImpl.iscAttachDatabase(AbstractJavaGDSImpl.java:370)
at org.firebirdsql.jca.FBManagedConnection.<init>(FBManagedConnection.java:89)
at org.firebirdsql.jca.FBManagedConnectionFactory.createManagedConnection(FBManagedConnectionFactory.java:470)
at org.firebirdsql.jca.FBStandAloneConnectionManager.allocateConnection(FBStandAloneConnectionManager.java:69)
at org.firebirdsql.jdbc.FBDataSource.getConnection(FBDataSource.java:119)
at org.firebirdsql.jdbc.FBDriver.connect(FBDriver.java:131)
at java.sql.DriverManager.getConnection(DriverManager.java:525)
at java.sql.DriverManager.getConnection(DriverManager.java:140)
at de.intermoves.eubicon.TestCharSet.main(TestCharSet.java:67)

Roman Rokytskyy has commented this in message 88296 of the firebird-support list by:

"UTF8 is however defined in Firebird, the corresponding one in Java is UTF-8

Please fill a bug report for Jaybird - there is some problem in name
resolution of the properties - it should not cause such exception. The
expected behavior would be an exception that the character set is unknown."

According to "http://java.sun.com/j2se/1.5.0/docs/guide/intl/encoding.doc.html", used at August 21th, 2007, UTF8 seems to be a valid java name for an unicode encoding.

UTF8 is a "Cannonical Name for the http://java.io and java.lang API", UTF-8 is the "Canonical Name for java.nio API".

The following class, that is a variant of the given example,
produces the reported error on my computer:

package de.intermoves.eubicon;

import java.util.Properties;

public class TestCharSet {

public static void main(String args[]) throws Exception {
String databaseURL = "jdbc:firebirdsql://localhost/E:\\data\\projekte\\eubicon\\CSIntermoves\\application\\supplier\\222.333_139041777\\data\\Data.fdb";

String user = "sysdba";
String password = "masterkey";
String driverName = "org\.firebirdsql\.jdbc\.FBDriver";

java\.sql\.Driver d = null;
java\.sql\.Connection c = null;
java\.sql\.Statement s = null;
java\.sql\.ResultSet rs = null;

try \{
  
  try \{
Class\.forName\("org\.firebirdsql\.jdbc\.FBDriver"\);
  \} catch \(java\.lang\.ClassNotFoundException e\) \{
// A call to Class\.forName\(\) forces us to consider this exception :\-\)\.\.\.
System\.out\.println\("Firebird JCA\-JDBC driver not found in class path"\);
System\.out\.println\(e\.getMessage\(\)\);
return;
  \}

  
  
  // At this point the driver should be registered with the driver manager\.
  // Try to find the registered driver that recognizes interbase URLs\.\.\.
  try \{
// We pass the entire database URL, but we could just pass "jdbc:interbase:"
d = java\.sql\.DriverManager\.getDriver\(databaseURL\);
System\.out\.println\("Firebird JCA\-JDBC driver version " \+
    d\.getMajorVersion\(\) \+
    "\." \+
    d\.getMinorVersion\(\) \+
    " registered with driver manager\."\);
  \} catch \(java\.sql\.SQLException e\) \{
System\.out\.println\("Unable to find Firebird JCA\-JDBC driver among the registered drivers\."\);
return;
  \}
  
  try \{
Properties props = new Properties\(\);
props\.put\("user", "sysdba"\);
props\.put  \("password", "masterkey"\);
props\.put  \("charSet", "UTF8"\);
<//props.put>  \("encoding", "UTF8"\);
c = java\.sql\.DriverManager\.getConnection\(databaseURL, props\);
System\.out\.println\("Connection established\."\);
  \} catch \(java\.sql\.SQLException e\) \{
e\.printStackTrace\(\);
System\.out\.println\("Unable to establish a connection through the driver manager\."\);
showSQLException\(e\);
return;
  \}
// This finally clause will be executed even if "return" was called in case of any exceptions above\.

} finally {
System.out.println("Closing database resources and rolling back any changes we made to the database.");

// Now that we're all finished, let's release database resources\.
try \{ if \(rs\!=null\) rs\.close\(\); \} catch \(java\.sql\.SQLException e\) \{ showSQLException\(e\); \}
try \{ if \(s\!=null\) s\.close\(\); \} catch \(java\.sql\.SQLException e\) \{ showSQLException\(e\); \}

// Before we close the connection, let's rollback any changes we may have made\.
try \{ if \(c\!=null\) c\.rollback\(\); \} catch \(java\.sql\.SQLException e\) \{ showSQLException\(e\); \}
try \{ if \(c\!=null\) c\.close\(\); \} catch \(java\.sql\.SQLException e\) \{ showSQLException\(e\); \}

}
}
// Display an SQLException which has occured in this application.
private static void showSQLException(java.sql.SQLException e) {
// Notice that a SQLException is actually a chain of SQLExceptions,
// let's not forget to print all of them...
java.sql.SQLException next = e;
while (next != null) {
System.out.println(next.getMessage());
System.out.println("Error Code: " + next.getErrorCode());
System.out.println("SQL State: " + next.getSQLState());
next = next.getNextException();
}
}
}

Commits: af36424

@firebird-automations
Copy link
Author

Modified by: Roman Rokytskyy (rrokytskyy)

Fix Version: Jaybird 2.2 [ 10053 ]

@firebird-automations
Copy link
Author

Commented by: Nestor Arturo Ramírez Moreno (ness2099)

First of all, you have a mistake in the sentences: props.put ("charSet", "UTF8");
You have to write "charset".

Second. you have to write after that the line: props.put("lc_ctype", "ISO8859_1");

The fixed code is:

                    Class\.forName\("org\.firebirdsql\.jdbc\.FBDriver"\);
		String databaseURL = "jdbc:firebirdsql://localhost/C:\\\\databases\\\\firebird\\\\example\.FDB"; 
		Properties props = new Properties\(\);
		props\.put\("user", "sysdba"\);
		props\.put \("password", "masterkey"\);
		props\.put \("charset", "UTF8"\); 
		props\.put\("lc\_ctype", "ISO8859\_1"\);
		jdbcConnection = DriverManager\.getConnection\(databaseURL, props\);

@firebird-automations
Copy link
Author

Commented by: Roman Rokytskyy (rrokytskyy)

No, the "charSet" is correct name. The issue is that instead of using "UTF-8" he used "UTF8", which caused null to be added to DPB and thus the error. But as I said, the driver should not cause such errors - property should be either completely ignored or should throw the exception before.

@firebird-automations
Copy link
Author

Modified by: Roman Rokytskyy (rrokytskyy)

status: Open [ 1 ] => Closed [ 6 ]

resolution: Fixed [ 1 ]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant