[ 
https://issues.apache.org/jira/browse/TOMEE-1537?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14392829#comment-14392829
 ] 

CHERANTHIAN MUTHUVINAYAGAM commented on TOMEE-1537:
---------------------------------------------------

Hi [~romain.manni-bucau]

I am Cheran and also working in John's team. I like to add more details to the 
bug.

The following code snippet (simplified) is used to construct the propertiest.
{code:borderStyle=solid}
// Define individual property
String LINE_SEPARATOR = System.getProperty("line.separator");
String jdbcUrlProperty = "jdbcUrl=jdbc:sqlserver://IN08268\\SQLEXPRESS";
String userNameProperty = "username=sa";
String passwordProperty = "password=laB+raT";
String defaultAutoCommitProperty =  "defaultAutoCommit=true";

// Construct properties
String definitionArgumentValue = jdbcUrlProperty + LINE_SEPARATOR + 
userNameProperty + LINE_SEPARATOR + passwordProperty + LINE_SEPARATOR + 
defaultAutoCommitProperty; 

{code}

When passing definitionArgumentValue to DataSourceFactory.create method removes 
'\\' the character which causes the getConnection to throw exception. The 
workaround escape the character as below. 

{code}
String definitionArgumentValue = jdbcUrlProperty.replace("\\", "\\\\") + 
LINE_SEPARATOR + userNameProperty + LINE_SEPARATOR + passwordProperty + 
LINE_SEPARATOR + defaultAutoCommitProperty; 
{code}

My concern with workaround is that I am be reading jdbc property url value from 
database and the caller of the DataSourceFactory.create method requires to 
escape the character before call it. Now the caller is exposed to the 
DataSourceFactory implementation and depends on it. In future, if the 
implementation is changed (may be remote chance) to parse the define parameter 
value by line separator, it will break the caller implementation.








> DataSourceFactory.create method removes the single backslash from MS SQL 
> Server jdbcUrl string that contains SQL Server instance name that causes 
> dataSoruce.getConnection() to throw SQLServerException.
> ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: TOMEE-1537
>                 URL: https://issues.apache.org/jira/browse/TOMEE-1537
>             Project: TomEE
>          Issue Type: Bug
>    Affects Versions: 1.7.1
>         Environment: Windows, Sql Server 2012, MS Sql Server JDBC Driver 4
>            Reporter: John Pratt
>            Priority: Critical
>
> If you pass in a valid connection string to the DataSourceFactory.create 
> method that contains a single backslash i.e., 
> jdbcUrl=jdbc:sqlserver://IN08268\SQLEXPRESS. The DataSource factory 
> implementation parses the “definition” String as java.util.Properties. 
> Parsing the string as java.util.Properties removes the single backslash 
> character that cause JDBC driver to fail.
> There is a workaround you could do to replace the single backslash with 
> double backslash in the jdbcUrl property (but this is an invalid conection 
> url for sql server). 



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to