You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/docs/asciidoc/appendices/characterencoding/characterencoding.adoc
+7-7Lines changed: 7 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -46,7 +46,7 @@ These issues were addressed in Firebird 2.0 and at the moment nothing prevents d
46
46
A developer must ensure two things to enable use of Unicode characters in the database and the application:
47
47
48
48
. The database objects must be defined with the `UTF8` character set;
49
-
this can be done by either creating database with default `UTF8` character set or by adding `CHARACTER SET UTF8` clause to the column or domain definitions.
49
+
this can be done by either creating the database with a default character set of `UTF8`, or by adding the `CHARACTER SET UTF8` clause to column or domain definitions.
50
50
. The `encoding` connection property in the JDBC driver has to be set to `UTF8`;
51
51
this can be done in several ways: the easiest one is to add the appropriate parameter to the JDBC URL (see the first example), another possibility is to use appropriate method of the `DriverManager` class (see the second example).
52
52
Applications that use `DataSource` interface to obtain the database connections also have access to the
@@ -77,10 +77,10 @@ There are a few limitations related to using the `UTF8` character set:
77
77
78
78
* It is not possible to create Unicode columns longer than 8191 Unicode characters;
79
79
this limitation is caused by the fact that the longest possible `VARCHAR` column can occupy 32765 bytes (32767 for `CHAR` columns) and a single `UTF8` character can occupy up to four bytes.
80
-
* It is not possible to index Unicode columns longer than 1023 characters -- or 2047 characters in Firebird 4.0 with a page size of 32 kilobytes;
81
-
this limitation is caused by the fact that the longest index key cannot be longer than a quarter of the database page, which has a maximum of 16k ([.since]_Firebird 4.0_ 32k) and the before mentioned fact that each `UTF8` character can occupy up to four bytes.
80
+
* It is not possible to index Unicode columns longer than 2047 characters -- this requires a page size of 32 kilobytes;
81
+
this limitation is caused by the fact that the longest index key cannot be longer than a quarter of the database page, which has a maximum of 32k and the fact that each `UTF8` character can occupy up to four bytes.
82
82
83
-
It should be mentioned that using Unicode character set might cause noticeable performance degradation when the database is accessed over wide-area networks.
83
+
Using the `UTF8` character set might cause noticeable performance degradation when the database is accessed over wide-area networks.
84
84
This mainly applies to the cases when non-latin characters are stored in the database, as those characters will require two or more bytes, which in turn might cause additional roundtrips to the server to fetch data.
85
85
86
86
==== The NONE character set
@@ -91,17 +91,17 @@ When the `NONE` character set is used, Jaybird does not know how to interpret th
91
91
The only choice that is left to Jaybird is to construct a string using the default character set of the JVM, which usually matches the regional settings of the operating system and can be accessed from within the JVM through the `file.encoding` system property.
92
92
93
93
With connection character set `NONE`, Jaybird uses the explicit character set of `CHAR`, `VARCHAR` and `BLOB SUB_TYPE TEXT` columns for the conversion.
94
-
This addresses most of the problems described in this paragraph, except for columns without an explicit character set (i.e. their character set is `NONE`).
94
+
This addresses most of the problems described in this section, except for columns without an explicit character set (i.e. their character set is `NONE`).
95
95
96
96
It is clear that a conversion using default character set that happens inside the JVM can lead to errors when the same content is accessed from two or more different Java Virtual Machines that have different configuration.
97
97
One application running on the computer with, for example, Russian regional settings saves the Russian text (the default character set of the JVM is Cp1251) and another application running on computer with German regional settings (default character set is Cp1252) will read in such case some special or accented characters.
98
98
However, when all client applications run on the same OS with the same regional settings, in most cases this will not have any severe consequences, except probably wrong sorting order or uppercasing on the server side.
99
99
100
100
On Linux and other Unix platforms, it might have more severe consequences as it is very common that regional settings are not configured and that the default "C" locale is used and the non-ASCII characters will be replaced with question marks ("?").
101
101
102
-
Therefore, application should use `NONE` character encoding as an encoding for a database and a connection only when at least one of the following is met:
102
+
Therefore, an application should only use `NONE` character encoding as an encoding for a database and a connection when at least one of the following is met:
103
103
104
-
* Database will contain only ASCII characters,
104
+
* The database will contain only ASCII characters,
105
105
* It is guaranteed that all Java Virtual Machines accessing the database will have the same default encoding that can correctly handle all characters stored in the database,
106
106
* All columns have an explicit character set.
107
107
When columns have an explicit character set (other than `NONE`) and connection character set `NONE` is used, Firebird will send an identifier of the character set of each column, and Jaybird will use that character set for the conversion.
Copy file name to clipboardExpand all lines: src/docs/asciidoc/appendices/jdbcescape/jdbcescape.adoc
+3-2Lines changed: 3 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -333,7 +333,7 @@ Legend: X -- available in this mode.
333
333
|The current local time as a time value
334
334
335
335
|DAYNAME(date)
336
-
|Xfootnote:[Always returns English full names (e.g. Sunday)]
336
+
|Xfootnote:[Always returns English full names (e.g. "`Sunday`")]
337
337
|{nbsp}
338
338
|A character string representing the day component of `date`;
339
339
the name for the day is specific to the data source
@@ -510,5 +510,6 @@ With explicit length, `CHARACTER SET OCTETS` is appended.
510
510
* `(SQL_)LONGVARBINARY`, `(SQL_)BLOB` will be cast to `BLOB SUB_TYPE BINARY`
511
511
* `(SQL_)TINYINT` is mapped to `SMALLINT`
512
512
* `(SQL_)ROWID` is not supported as length of `DB_KEY` values depend on the context
513
-
* `(SQL_)DECIMAL` and `(SQL_)NUMERIC` without precision and scale are passed as is, in current Firebird versions, this means the value will be equivalent to `DECIMAL(9,0)` (which is equivalent to `INTEGER`)
513
+
* `(SQL_)DECIMAL` and `(SQL_)NUMERIC` without precision and scale are passed as is.
514
+
In current Firebird versions, this means the value will be equivalent to `DECIMAL(9,0)`/`NUMERIC(9,0)`, which is equivalent to `INTEGER`.
514
515
* Unsupported/unknown _SQLtype_ values (or invalid length or precision and scale) are passed as is to cast, resulting in an error from the Firebird engine if the resulting cast is invalid
Copy file name to clipboardExpand all lines: src/docs/asciidoc/appendices/systemproperties/systemproperties.adoc
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -123,6 +123,8 @@ The following system properties control other global behaviour of Jaybird.
123
123
124
124
`org.firebirdsql.jna.syncWrapNativeLibrary`::
125
125
Set to true to add a synchronization proxy around the native client library.
126
+
+
127
+
This can be used to address thread-safety issues with older client libraries (Firebird 2.1 and older, as far as we know).
126
128
`org.firebirdsql.datatypeCoderCacheSize`::
127
129
Integer value for the number of encoding specific data type coders cached (default and minimum is 1).
128
130
Setting to a higher value may improve performance, most common use case is connection character set `NONE` with a database that uses more than one character set for its columns.
Copy file name to clipboardExpand all lines: src/docs/asciidoc/chapters/connection/connection.adoc
+50-41Lines changed: 50 additions & 41 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,8 @@ Jaybird is a regular JDBC driver and supports two primary ways to obtain connect
6
6
[[connection-drivermanager]]
7
7
=== Obtaining connection java.sql.DriverManager
8
8
9
-
`java.sql.DriverManager` was the first connection factory in Java. It is based on the concept of the JDBC URL, a string that uniquely identifies the database to connect.
9
+
`java.sql.DriverManager` is a database connection factory introduced with JDBC 1.
10
+
It is based on the concept of the JDBC URL, a string that uniquely identifies the database to connect.
10
11
The driver manager then checks which driver(s) -- if any -- can establish a connection.
11
12
12
13
There is also support to specify additional connection parameters, like username and password.
JDBC subprotocol, identifies driver to use, in this case Jaybird
24
25
* `//localhost:3050/c:/database/example.fdb`
25
26
+
26
27
This is a database specific part, and identifies the database for the driver to connect, in the case of Jaybird that is `//<host>:<port>/<path to database>`
27
28
28
29
The first part, `jdbc:firebird:` or `jdbc:firebirdsql:`, is required by JDBC and specifies the so-called protocol and subprotocol for the JDBC connection.
29
-
In other words, the type of connection that the application wants to obtain, in this example it is a connection to a Firebird database.
30
+
In other words, it specifies the type of connection that the application wants to obtain, in this example, a connection to a Firebird database.
30
31
31
32
An example of obtaining a connection is shown below.
32
33
@@ -40,14 +41,13 @@ import java.sql.*;
40
41
public class HelloServer {
41
42
42
43
public static void main(String[] args) throws Exception {
@@ -56,7 +56,7 @@ The first line of this code is important -- it tells Java to load the Jaybird JD
56
56
As required by the JDBC specification, at this point driver registers itself with `java.sql.DriverManager`.
57
57
58
58
Since Java 6 (JDBC 4), explicitly loading the driver using `Class.forName("org.firebirdsql.jdbc.FBDriver")` is no longer necessary, except when the driver is not on the system class path.
59
-
Examples where it may be necessary to explicitly load the driver are web applications that include the driver in the deployment.
59
+
Examples where it may be necessary to explicitly load the driver are web applications that include the driver in the deployment (e.g. in `WEB-INF/lib` of the WAR).
60
60
There, the driver is not on the system class path, so it will need to be loaded explicitly.
61
61
62
62
We will leave out usages of `Class.forName` in further examples, they will work because of automatic driver loading.
@@ -78,8 +78,8 @@ The JDBC specification requires that during class initialization the driver regi
78
78
....
79
79
Class.forName("org.firebirdsql.jdbc.FBDriver");
80
80
....
81
-
3. The JDBC driver name is listed in the `jdbc.drivers` system property.
82
-
Multiple drivers can be separated using a colon (`:`).
81
+
3. The JDBC driver class name is listed in the `jdbc.drivers` system property.
82
+
Multiple drivers can be separated using a colon ('```:```').
83
83
+
84
84
You can specify the value of this property during JVM startup:
85
85
+
@@ -129,18 +129,15 @@ import java.util.*;
129
129
public class HelloServerWithEncoding {
130
130
131
131
public static void main(String[] args) throws Exception {
@@ -149,10 +146,10 @@ public class HelloServerWithEncoding {
149
146
The `user` and `password` properties are defined in JDBC. All other property names, like `encoding` here, are driver-specific.
150
147
151
148
Additional properties, for example the SQL role for the connection can be added to the `props` object.
152
-
The list of properties available in Jaybird can be found in <<Extended connection properties>>.
149
+
The list of properties available in Jaybird can be found in <<connectionproperties>>.
153
150
154
-
It is not always possible to use the above described method.
155
-
Jaybird also provides a possibility to specify extended properties in the JDBC URL.
151
+
It is not always possible to use the above described method to add properties.
152
+
Jaybird also provides a possibility to specify connection properties in the JDBC URL.
156
153
157
154
.Extended JDBC URL format
158
155
....
@@ -163,10 +160,8 @@ jdbc:firebird://host[:port]/<path to db>?<properties>
163
160
164
161
The example below shows the specification for extended JDBC properties in the URL.
165
162
166
-
In this case extended properties are passed together with the URL using the HTTP-like parameter passing scheme: first comes the main part of the URL, then `"?"`, then name-value pairs separated with `&` or `;`.
167
-
This example is equivalent to the previous example.
168
-
169
-
NOTE: Jaybird only supports URL encoding in Jaybird 4 and higher.
163
+
In this case extended properties are passed together with the URL using the HTTP-like parameter passing scheme: first comes the main part of the URL, then '```?```', then name-value pairs separated with '```&```' or '```;```'.
164
+
The following example is equivalent to the previous example.
NOTE: Jaybird only supports URL encoding in Jaybird 4 and higher.
183
+
187
184
UTF-8 URL encoded values (and keys) can be used in the query part of the JDBC URL.
188
185
189
-
As a result of this change, the following previously unsupported characters can be used in a connection property value when escaped:
186
+
This can be used to include otherwise unsupported characters in a connection property value:
190
187
191
188
* `;` escaped as `%3B`
192
189
* `&` escaped as `%26`
190
+
* `{plus}` escaped as `%2B`
191
+
+
192
+
A {plus} in the query part means _space_ (0x20), so occurrences of `{plus}` (_plus_) need to be escaped;
193
+
make sure to do this for _base64_ encoded values of `dbCryptConfig`, or better yet use the _base64url_ encoding instead.
194
+
* `%` escaped as `%25`.
195
+
+
196
+
A `%` in the query part introduces an escape, so occurrences of `%` (_percent_) need to be escaped.
197
+
* Optionally, a _space_ (0x20) can be escaped as {plus}
193
198
194
-
In addition, the following characters must also be escaped:
195
-
196
-
* `{plus}` in the query part now means _space_ (0x20), so occurrences of `{plus}` (_plus_) need to be escaped as `%2B`;
197
-
make sure to do this for _base64_ encoded values of `dbCryptConfig` (or use the _base64url_ encoding instead)
198
-
* `%` in the query part now introduces an escape, so occurrences of `%` (_percent_) need to be escaped as `%25`
199
-
200
-
URL encoding can also be used to encode any unicode character in the query string.
199
+
URL encoding can also be used to encode any Unicode codepoint in the query string.
201
200
Jaybird will always use UTF-8 for decoding.
202
201
203
202
Invalid URL encoded values will throw a `SQLNonTransientConnectionException`.
@@ -213,6 +212,15 @@ Data sources can be created and configured using code or bean introspection, loo
213
212
214
213
Jaybird itself provides one `javax.sql.DataSource` implementation, `org.firebirdsql.ds.FBSimpleDataSource`, which is a plain factory of connections, without connection pooling.
215
214
215
+
[TIP]
216
+
====
217
+
If you need connection pooling, use a third-party connection pool library like https://brettwooldridge.github.io/HikariCP/[HikariCP^], https://commons.apache.org/proper/commons-dbcp/[DBCP^], or https://www.mchange.com/projects/c3p0/[c3p0^].
218
+
Application servers, and for example Tomcat, also provide built-in connection pool support.
219
+
Consult their documentation for more information.
220
+
221
+
See also <<connection-pooling>>.
222
+
====
223
+
216
224
A simple example of creating a data source and obtaining a connection via a `DataSource` object is shown below.
217
225
218
226
[source,java]
@@ -237,7 +245,7 @@ public class HelloServerDataSource {
@@ -302,6 +310,8 @@ The `DataSource` implementation supports all connection properties available to
302
310
====
303
311
Manually binding to JNDI like shown above is uncommon.
304
312
If you find yourself copying this code, rethink what you're doing.
313
+
314
+
In fact, use of JNDI is extremely uncommon these days.
305
315
====
306
316
307
317
[[driver-types]]
@@ -320,6 +330,7 @@ The `PURE_JAVA` type (JDBC Type 4) uses a pure Java implementation of the Firebi
320
330
This type is recommended for connecting to a remote database server using TCP/IP sockets.
321
331
No installation is required except adding the JDBC driver to the class path.
322
332
This type of driver provides the best performance when connecting to a remote server.
333
+
Some Jaybird features are only available in the pure Java implementation.
323
334
324
335
To obtain a connection using the `PURE_JAVA` driver type you have to use a JDBC URL as shown in <<Obtaining connection java.sql.DriverManager>>.
325
336
@@ -343,9 +354,7 @@ If _portNumber_ is not specified, it defaults to `3050`.
343
354
344
355
In theory, even `<database-coordinates>` and _databaseName_ are optional, but this requires specifying the database name using connection property `databaseName`, which is possible, but not recommended.
345
356
346
-
When using `javax.sql.DataSource` implementation, you can specify either `"PURE_JAVA"` or `"TYPE4"` driver type, however this type is used by default.
347
-
348
-
Some URL examples
357
+
When using `javax.sql.DataSource` implementation, you can specify either `"PURE_JAVA"` or `"TYPE4"` driver type, however this type is already used by default.
349
358
350
359
.Pure Java URL examples
351
360
[listing]
@@ -403,7 +412,7 @@ The following JDBC URL syntax is supported:
403
412
----
404
413
405
414
[.since]_Jaybird 5_ Since Jaybird 5, all URLs supported by fbclient can be used.
406
-
The supported URLs depend on the fbclient version and the OS (e.g. XNET and WNET are Windows only, and WNET support will be removed in Firebird 5).
415
+
The supported URLs depend on the fbclient version and the OS (e.g. XNET and WNET are Windows only, and WNET support has been removed in Firebird 5).
407
416
408
417
When connecting to a local database server using the `LOCAL` driver, you should use following:
409
418
@@ -545,11 +554,11 @@ The following JDBC URL syntax is supported:
545
554
[listing,subs=+quotes]
546
555
----
547
556
<embedded-url> ::=
548
-
jdbc:firebird[sql]:embedded:_dbname-or-alias_
557
+
jdbc:firebird[sql]:embedded:__dbname-or-alias__
549
558
----
550
559
551
560
In practice, the URL accepts the same `<fbclient-url>` values as described for `NATIVE`.
552
-
That is, the embedded server acts as client library (i.e. you get the same Type 2 behavior as you would get with using "native").
561
+
That is, the embedded server also acts as client library (i.e. you get the same Type 2 behavior as you would get with using "native").
553
562
554
563
This driver tries to load `fbembed.dll/libfbembed.so` (the name used in Firebird 2.5 and earlier) and `fbclient.dll/libfbclient.so`.
555
564
@@ -570,7 +579,7 @@ This implies the same restrictions on the classloader that will load the Jaybird
570
579
571
580
By default, the Firebird embedded library opens databases in exclusive mode.
572
581
This means that this particular database is accessible only to one Java virtual machine.
573
-
This can be changed by the `ServerMode` setting in `firebird.conf`.
582
+
This can be changed with the `ServerMode` setting in `firebird.conf`.
574
583
575
584
[[driver-ooremote]]
576
585
==== OOREMOTE type
@@ -608,7 +617,7 @@ Each time a connection is opened via `DriverManager`, a new physical connection
608
617
It is closed when the connection is closed.
609
618
To avoid the overhead of creating connections, you can use a connection pool implementation to maintain a cache of open physical connections that can be reused between user sessions.
610
619
611
-
Since Jaybird 3, Jaybird no longer provides a connection pool.
620
+
Since Jaybird 3, Jaybird no longer provides its own connection pool implementation.
612
621
If you need a `javax.sql.DataSource` implementation that provides a connection pool, either use the connection pool support of your application server, or consider using https://brettwooldridge.github.io/HikariCP/[HikariCP^], https://commons.apache.org/proper/commons-dbcp/[DBCP^], or https://www.mchange.com/projects/c3p0/[c3p0^].
0 commit comments