Subject | Re: FBWrappingDataSource and character encodings |
---|---|
Author | sergeybervinov |
Post date | 2003-03-26T09:16:46Z |
> I presume by this you mean that this technique works?It's quite unusual situation to receive such questions from
> If so, I'll add it to the FAQ.
developers ;-)
Yes, it works. I did almost as it described in your FAQ "42 - Can you
give me some code examples?" in "Data Source Example". But
information in "Data Source Example" is old. There are the following
lines in this section:
FBConnectionRequestInfo cri = dataSource.getConnectionRequestInfo();
cri.setProperty(GDS.isc_dpb_lc_ctype, "NONE");
cri.setProperty(GDS.isc_dpb_num_buffers, 1);
cri.setProperty(GDS.isc_dpb_sql_dialect, 3);
dataSource.setConnectionRequestInfo(cri);
It's wrong because there is no more constants in GDS class and now
they are declared in ISCConstants class. I saw this in your source
code and used ISCConstants instead of GDS.
Bellow you can see my source code.
------------------------------------------------------------
public class DatabaseRegistrationInformation {
private String alias;
private String host;
private int port = 3050;
private String name;
private String user;
private String password;
...
...
...
public String getDataSourceDatabase() {
return "//" + host + ":" + port + "/" + name;
}
}
public class Server extends AbstractServer implements BusinessLogic {
private static Hashtable servers;
public static void init(ServletContext context) {
if (servers == null) {
try {
Class.forName
("org.firebirdsql.jdbc.FBDriver").newInstance();
Config.load(context);
servers = new Hashtable(Config.getDatabasesCount());
DatabaseRegistrationInformation database;
for (Enumeration e = Config.getDatabases();
e.hasMoreElements();) {
database = (DatabaseRegistrationInformation)
e.nextElement();
servers.put(database.getAlias(), new Server
(database));
}
System.out.println("[MobileAdmin Server] " +
servers.size() + " server instance" + (servers.size()>1?"s":"") + "
are started.");
} catch (Exception ex) {
System.err.print("[MobileAdmin Server] ");
ex.printStackTrace();
throw new MobileRuntimeException("Could not create
and/or configurate the server instance!");
}
}
}
public static BusinessLogic getInstance(String databaseAlias) {
return databaseAlias == null
? null
: (BusinessLogic)servers.get(databaseAlias);
}
private DatabaseRegistrationInformation
databaseRegistrationInformation;
private FBWrappingDataSource ds;
public Server(DatabaseRegistrationInformation
databaseRegistrationInformation) {
this.databaseRegistrationInformation =
databaseRegistrationInformation;
try {
this.ds = new FBWrappingDataSource();
ds.setDatabase
(databaseRegistrationInformation.getDataSourceDatabase());
ds.setUserName(databaseRegistrationInformation.getUser());
ds.setPassword(databaseRegistrationInformation.getPassword
());
ds.setIdleTimeoutMinutes(Config.getIdleTimeoutMinutes());
ds.setPooling(true);
ds.setMinSize(Config.getMinConnections());
ds.setMaxSize(Config.getMaxConnections());
ds.setLoginTimeout(10);
ds.getTransactionParameters().setTransactionIsolationName
(FBTpb.TRANSACTION_READ_COMMITTED);
FBConnectionRequestInfo cri = ds.getConnectionRequestInfo
();
cri.setProperty(ISCConstants.isc_dpb_lc_ctype,
Config.DATABASE_DRIVER_ENCODING);
cri.setProperty(ISCConstants.isc_dpb_sql_dialect, 3);
ds.setConnectionRequestInfo(cri);
} catch (Exception ex) {
throw mobileRuntimeException(ex);
}
}
private Connection getConnection() {
try {
Connection connection = ds.getConnection();
connection.setAutoCommit(false);
return connection;
} catch (Exception ex) {
throw mobileRuntimeException(ex);
}
}
...
...
...
}
------------------------------------------------------------
Best regards,
Sergey Bervinov (James Advent)
Java/WEB Programmer
EMail: sergey_bervinov@...
sergey_bervinov@...
ICQ: 98681963