Home > Back-end >  Ask ace to com. Microsoft. Essentially. JDBC. SQLServerException: ', 'near a syntax error.
Ask ace to com. Microsoft. Essentially. JDBC. SQLServerException: ', 'near a syntax error.

Time:10-04

Try a book city background system, connection the SQL server database connection is no problem,
The update operation have the problem when the parameter is set to static can update the database inside the content of the
To use? Is an error, a placeholder, strives for the bosses give directions!


Test source code
Public void updateBook () {
BookDao. UpdateBook (new Book (5, "mxyisdog", "DHXDHXHHH", new BigDecimal (32), 123, 44, "static/images"));
}

Method of bookDao inside
Public int updateBook (Book Book) {
String SQL="update t_book set name=? , the author=? , price=? , the sales=? The stock=? , img_path=? Where id=?" ;
Return the update (SQL, book getName (), book. GetAuthor (), book. GetPrice (), book. GetSales (), book. GetStock (), book. GetImgPath (), the book, getId ());
}


The IDEA of an error log

On March 20, 2020 4:58:52 afternoon com. Alibaba. Druid. Support. Logging. JakartaCommonsLoggingImpl info
Information: {} dataSource - 1 inited
Java. SQL. SQLException: com. Microsoft. Essentially, JDBC. SQLServerException: ', 'near a syntax error, Query, update t_book set name=? , the author=? , price=? , the sales=? The stock=? , img_path=? Where id=? The Parameters: [mxyisdog DHXDHXHHH, 32, 123, 44, static/images, 5]
At org.apache.com mons. Dbutils. QueryRunner. Rethrow (QueryRunner. Java: 542)
At org.apache.com mons. Dbutils. QueryRunner. Update (QueryRunner. Java: 599)
At com. Atguigu. Dao. Impl. BaseDao. Update (BaseDao. Java: 21)
At com. Atguigu. Dao. Impl. BookDaoImpl. UpdateBook (25) BookDaoImpl. Java:
At com. Atguigu. Test. BookDaoImplTest. UpdateBook (BookDaoImplTest. Java: 27)
At sun. Reflect. NativeMethodAccessorImpl. Invoke0 (Native Method)
At sun. Reflect. NativeMethodAccessorImpl. Invoke (NativeMethodAccessorImpl. Java: 62)
At sun. Reflect. DelegatingMethodAccessorImpl. Invoke (43) DelegatingMethodAccessorImpl. Java:
The at Java. Lang. Reflect. Method. Invoke (498) Method. The Java:
The at org. Junit. Runners. Model. FrameworkMethod $1. RunReflectiveCall (FrameworkMethod. Java: 50)
The at org. Junit. Internal. Runners. Model. ReflectiveCallable. Run (ReflectiveCallable. Java: 12)
The at org. Junit. Runners. Model. FrameworkMethod. InvokeExplosively (FrameworkMethod. Java: 47)
The at org. Junit. Internal. Runners. Statements. InvokeMethod. Evaluate (InvokeMethod. Java: 17)
The at org. Junit. Runners. ParentRunner. RunLeaf (ParentRunner. Java: 325)
The at org. Junit. Runners. BlockJUnit4ClassRunner. RunChild (BlockJUnit4ClassRunner. Java: 78)
The at org. Junit. Runners. BlockJUnit4ClassRunner. RunChild (BlockJUnit4ClassRunner. Java: 57)
The at org. Junit. Runners. ParentRunner $3. The run (ParentRunner. Java: 290)
The at org. Junit. Runners. ParentRunner $1. The schedule (ParentRunner. Java: 71)
The at org. Junit. Runners. ParentRunner. RunChildren (ParentRunner. Java: 288)
The at org. Junit. Runners. ParentRunner. Access the $000 (ParentRunner. Java: 58)
At org. Junit. Runners. ParentRunner $2. The evaluate (ParentRunner. Java: 268)
The at org. Junit. Runners. ParentRunner. Run (ParentRunner. Java: 363)
The at org. Junit. Runner. JUnitCore. Run (JUnitCore. Java: 137)
At com. Intellij. Takeup. JUnit4IdeaTestRunner. StartRunnerWithArgs (JUnit4IdeaTestRunner. Java: 68)
At com. Intellij. Rt. Execution. Junit. IdeaTestRunner $Repeater. StartRunnerWithArgs (IdeaTestRunner. Java: 47)
At com. Intellij. Rt. Execution. Junit. JUnitStarter. PrepareStreamsAndStart (JUnitStarter. Java: 242)
At com. Intellij. Rt. Execution. Junit. JUnitStarter. Main (70) JUnitStarter. Java:

The Process finished with exit code 0

CodePudding user response:

May be caused by imgpath slashes, put all the need to use quotes around the string to replace the question mark

CodePudding user response:

reference 1st floor with ah response:
may be caused by imgpath slashes, before and after all the need to replace with a string of question marks quotes

Elder brother, I can't, add the quotes after an error com. Microsoft. Essentially. JDBC. SQLServerException: keyword 'FROM' near a syntax error, Query, update t_book set name='?

CodePudding user response:

You try every comma will add a space set name=? , the author=? Like this, give it a try

CodePudding user response:

I tried, the underlying SQL sure

You change the static/images to try other useless slashes of string, if not quote this wrong, that's the problem, slash
Update method where the breaking point, single step check parameters after replacement of SQL is right, has prompted abnormal wrong line number, you go take a look at yourself,
. Remember before debugging the Commons dbutils package download the source code, https://mvnrepository.com/artifact/commons-dbutils/commons-dbutils
Note that version
As to add Spaces quotes these don't try, meaningless,

CodePudding user response:

reference 4 floor Little5 response:
I tried, the underlying SQL sure

You change the static/images to try other useless slashes of string, if not quote this wrong, that's the problem, slash
Update method where the breaking point, single step check parameters after replacement of SQL is right, has prompted abnormal wrong line number, you go take a look at yourself,
. Remember before debugging the Commons dbutils package download the source code, https://mvnrepository.com/artifact/commons-dbutils/commons-dbutils
Note that version
As to add Spaces quotes these don't try, meaningless,


Predecessors slashes replaced, breakpoint page, apparently still won't do,,,,

CodePudding user response:

The
reference 3 floor chengzi11 response:
you try every comma will add a space set name=? nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related