2013-11-23 2 views
1

Какова будет моя строка соединения, если имя моего SQL Server 2012: JOSEAN\REGULUS?Строка соединения JDBC SQL Server с JSP вызывает ошибку «Illegal escape character»

"jdbc:sqlserver://JOSEAN\REGULUS;databasename = BD12272" 

Однако, это вызвало ошибку компиляции:

Illegal escape character

Как это вызвало и как я могу решить это?

+0

Вы получаете ошибку? что именно вы подразумеваете под «не имея результатов»? – msturdy

+0

Если вы действительно делаете это в JSP, просто ... не делайте этого. – GreyBeardedGeek

ответ

0

Попробуйте вместо этого:

"jdbc:sqlserver://JOSEAN;instanceName=REGULUS;databaseName=BD12272" 
1

java documentation говорит:

A character preceded by a backslash (\) is an escape sequence and has special meaning to the compiler. The following table shows the Java escape sequences:

  • \t Insert a tab in the text at this point.
  • \b Insert a backspace in the text at this point.
  • \n Insert a newline in the text at this point.
  • \r Insert a carriage return in the text at this point.
  • \f Insert a formfeed in the text at this point.
  • \' Insert a single quote character in the text at this point.
  • \" Insert a double quote character in the text at this point.
  • \\ Insert a backslash character in the text at this point.

Ваша строка соединения имеет обратную косую черту, поэтому Java ожидает последовательность выхода и \ R не является (Illegal маскирующим).

Таким образом, вы должны обратный слеш и строка подключения должна выглядеть следующим образом:

"jdbc:sqlserver://JOSEAN\\REGULUS;databasename = BD12272" 
Смежные вопросы