Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

why my sql in jsp is error?  RSS feed

 
Wang Fong
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can use this SQL in MS Access get a result,but in jsp,it always show exception.

the SQL is: "select a.idno as idno,(select cname from employee where idno=a.testman) as tester from testask a"

however,if I use "select * from testask" in jsp ,it will be ok.
the error may locates at (select cname from employee where idno=a.testman),how to fix this?

thanks,

wang
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 37230
519
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wang,
Welcome to JavaRanch!

I'm not sure what you are trying to query. Is this based on user input or does it always return the list of all employees?

(Just so you know for the future, it's good practice to keep code out of the JSP and into Java.)
 
Wang Fong
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"keep code out of the JSP and into Java is a good suggestion".thanks.

I just did a test for the sql,if I use "select * from table",it will be ok in jsp,however,if I use "select field1 as field1,(select field2 from table2 where field3=a.field4) as field2 from table1 a" it will show exception.but the secnd sql statement in Ms Access cna run ok.

the two tables like:

table1
field1
field2
field3
field4
...

table2
field1
field2
field3
field4
...
 
Eugene Lucash
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
May be you JDBC driver to MSSQL don't support this kinds of queries.
Try to decomposite this query in two, or try to use ms's stored procedure.
Or even Try another Driver (there are Ms's , JTDS, JNetDirect drivers )
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!