I have to define the UTF8 character encoding connection parameter in the websphere JDBC datasource settings.
I didn't find any option to configure the connection parameter
?useUnicode=yes&characterEncoding=UTF-8
Eg:
jdbc:sqlserver://localhost/DatabaseName?useUnicode=yes&characterEncoding=UTF-8
Is there any way to configure the characterEncoding connection parameter in the Websphere JDBC data source ?
The closest setting that I see on the Microsoft SQL Server JDBC driver is sendStringParametersAsUnicode with values of true or false, which appears to be a way of getting PreparedStatement.setString and a few other methods to supply parameters to the database as unicode prior to the introduction of methods such as PreparedStatement.setNString in JDBC 4.0, which would always use unicode.
https://learn.microsoft.com/en-us/sql/connect/jdbc/setting-the-connection-properties?view=sql-server-ver15
If the database supports setting the property "characterEncoding", you can simply create a custom datasource property for it, with the value you need. If the database supports supports url connection (as in your example), you can also just include it as part of your connection URL, which can also be set as a custom datasource property.
Related
I have a properties file with database connection properties. Then, I use a transformation to load variables and use it as '${VARIABLE_NAME}' in the database connection. Then problem is when I need to set a Checkbox value (with boolean value).
The data base connection is MS SqlServer (Native) with Native (JDBC), And I need to set the "Use Integrated Security" property.
Somebody knows how can I do this? Thanks in advance.
Your problem is in connection with 'Use integrated Security'.
You know 'Use integrated Security' is use for windows authentication.
To do this , it is required to in place mssql-jdbc_auth dll in proper location in PDI.
Please follow the below instruction:-
Download MSSQL driver from [https://learn.microsoft.com/en-us/sql/connect/jdbc/download-microsoft-jdbc-driver-for-sql-server?view=sql-server-2017]
Copy "mssql-jdbc-8.4.1.jre8.jar" to your PDI lib location "..\data-integration70\lib".
Now the most important one is, you need to copy "mssql-jdbc_auth-8.4.1.x64.dll" to your PDI location "data-integration70\libswt\win64"
and "mssql-jdbc_auth-8.4.1.x86.dll" to your PDI location "data-integration70\libswt\win32"
[You will found both the dll from microsoft JDBC driver folder which one you have downloaded in step #1. And location will be "sqljdbc_8.4.1.0_enu\sqljdbc_8.4\enu\auth\x86" and "sqljdbc_8.4.1.0_enu\sqljdbc_8.4\enu\auth\x64"]
Now run the PDI and test your transformation.
Please let me know if you still found the issue.
How do I configure CommandTimeout (not Connect Timeout) from connection string in SQL Server?
I thought it'd be simple to find but apparently not. Below I added CommandTimeout=60. It doesn't seem to break anything, but I have no idea if it's actually working or not (and I can't find doc on this)
Data Source=someplace.com;Initial Catalog=MyDB;CommandTimeout=60;User Id=someID;Password=secret;
It's probably worth pointing out that setting the default command timeout via the connection string is possible in Microsoft.Data.SqlClient since version ~2.1.0. This package is the open source replacement for System.Data.SqlClient and is available from nuget
If you add e.g. ;Command Timeout=300 to your connection string and receive an error Keyword not supported: Command Timeout' you should check that you truly are using Microsoft.Data.SqlClient, and that its version is greater than 2.1; the question was posed before it was possible, but times have changed
Confirm, using the versions of:
Microsoft ActiveX Data Objects 6.1 Library
Microsoft ActiveX Data Objects Recordset 6.0 Library
The CommandTimeout - when set for the Connection object - works also for the ADO Queries following Connection Open.
I'm working with a Java web application backed by a Microsoft SQL Server. I have used nvarchar columns and my plan is to support Unicode characters. So in my JDBC layer I have used getNString() method from the result set and it works fine. However just for curiosity I changed all the getNString() methods to normal getString() methods and it also works fine displaying Unicode characters correctly.
I found the similar observation from below question as well
Should I be using JDBC getNString() instead of getString()?
Do you guys have any idea about this?
The presence of getNString and setNString is - in my opinion - a design mistake of JDBC. However, database systems that discern between (VAR)CHAR and N(VAR)CHAR can take this setter as a type hint to send the data in their specific format for N(VAR)CHAR. For getters there will usually be no difference as in most drivers, the data will have already been fetched before this method can be called, and a driver should know the proper conversion.
Specifically for the Microsoft SQL Server JDBC driver, with default configuration there is no difference between using setString or setNString: both will lead to the values being sent as unicode. This changes when the connection property sendStringParametersAsUnicode has been set to false.
See also NVARCHAR Support in Type 2 SQL Server 2008 JDBC Driver:
You do not need to use the JDBC 4 API to work with NVARCHAR (UCS-2)
data in SQL Server. Existing JDBC 3 APIs such as
getString/setString/updateString are used to get/set/update Unicode
values as Java Strings (which are always Unicode). The only thing to
be aware of when using the JDBC 3 methods is the setting of the
sendStringParametersAsUnicode property. This property is set to
'true' by default, which means that PreparedStatement and
CallableStatement parameters are sent to SQL Server in Unicode.
Changing the setting to 'false' allows the driver to save space in the
protocol by converting input parameter values to the character set of
the database when sending them.
That said, using the JDBC 4 API to work with NVARCHAR data has some
advantages. The main advantage is formal recognition of the NVARCHAR
type by the JDBC API, including accessor methods such as
getNString/setNString/updateNString. For example, the setNString
method can be used to send input parameter values to SQL Server in
Unicode, even if sendStringParametersAsUnicode is set to 'false'.
Put another way, with the default setting of
sendStringParametersAsUnicode=true, the JDBC 4 'N' methods behave the
same way as the JDBC 3/JDBC 4 non-'N' methods with respect to NVARCHAR
data.
For more information on the sendStringParametersAsUnicode connection property, see Setting the Connection Properties.
I have a spring boot JDBC Cofiguration A as below which works well,
Configuration A
spring.datasource.sqlserver.url=jdbc:sqlserver://localhost:1433;database=my-testdb
spring.datasource.sqlserver.user=user_101#server-product1
spring.datasource.sqlserver.password=password_101
spring.datasource.sqlserver.driver-class-name=com.microsoft.sqlserver.jdbc.SQLServerDriver
Configuration B below does not. Note that the url string does not have the database name in it. The database name is specified in a separate line, as one would expect to configure.
spring.datasource.sqlserver.url=jdbc:sqlserver://localhost:1433
spring.datasource.sqlserver.user=user_101#server-product1
spring.datasource.sqlserver.password=password_101
spring.datasource.sqlserver.database=my-testdb
spring.datasource.sqlserver.driver-class-name=com.microsoft.sqlserver.jdbc.SQLServerDriver
Cannot figure out why the database name cannot be specified in a separate line and has to be in the URL. Can anyone mention why this does not work?
Other configuration : Spring Boot, sqljdbc41.jar
Well that's how the Microsoft's SQL Server / Azure JDBC driver works, database name is a mandatory part of the URL, and not given in a "database" attribute.
Technically, it may be related to the fact that databases in SQL Server behave rather autonomously, they each have their own set of catalog views, you cannot switch between databases freely etc.
I'm trying to get data form a 2008r2 MSSql server using jruby and datamapper.
The only problem I've got this far is correct character coding in jruby.
Database uses Polish_CI_AS collation, testing field is populated with: "ą ę ś ć".
Fetching that field from within jruby results in: "uFFFD uFFFD uFFFD uFFFD" which are default replacement strings for utf-8.
I've tried setting the -E variable to windows-1250, it changes the characters displayed but as in Utf-8 they are displayed in the same manner. Also tried to include # encoding: Windows-1250, but it doesn’t help either.
I’m pretty sure it has something to do with datamapper or the db connection but jdbc does not supports (AFAIK) encoding variables.
UPDATE
My connection string: DataMapper.setup(:default, 'sqlserver://servername/database;instance=InstanceName;domain=DOMAIN')
The connection works well with MS JDBC, datamapper uses jTDS which uses UTF8 encoding as default.
I've checked the jTDS documentation and found that I needed to add: charset=cp1250; property at the end of my connection string. It all works well now.