• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

PreparedStatement to pass user input to MySQL not working

 
WeiJie Lim
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to pass a user-entered value from a jsp table to a MySQL database.

The pstmt Statement Object is not being recognized at the start =/ .

Any help is deeply appreciated :)

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
WeiJie Lim wrote:The pstmt Statement Object is not being recognized at the start =/ .


I do not know what you mean by that. Please TellTheDetails.

Also, this code should not be in a JSP. It should be in a Java class.
 
WeiJie Lim
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The error message is "pstmt cannot be resolved" , "size cannot be resolved to a variable", "name cannot be resolved to a variable", "year cannot be resolved to a variable"

Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:103)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:331)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:468)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:378)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:353)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:340)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:646)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:357)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)


Oh I see.. I am currently learning JSP now, so I have to do it in JSP =/.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As in, "this is a school assignment where they are making me use JSP inappropriately"? Or as in "I'm learning on my own and don'y know any other way"?
 
WeiJie Lim
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:As in, "this is a school assignment where they are making me use JSP inappropriately"? Or as in "I'm learning on my own and don'y know any other way"?


The former.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I shake my head at the poor state of teaching. Why teach you to do things the wrong way?

In any case, if you look at your JSP, you will see that you reference pstmt first on line 5, yet it is not declared until line 20. And even when it is declared, its scope is limited to inside the try block.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moreover, even if it were in scope, you are doing an UPDATE, not a SELECT. So what are you expecting to be able to "get" from the results?
 
Amit Ghorpade
Bartender
Posts: 2854
10
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is a bunch of further improvement possibilities in addition to what Bear said.
Like you have also obtained a Statement object which is not used, the connections to DB are not closed, nor do the name,size and year look defined anywhere, etc.
 
WeiJie Lim
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay I modified the code.. now the code looks better now, but there is still an error at line 39 which contains - " pstmt.executeUpdate();".

"org.apache.jasper.JasperException: An exception occurred processing JSP page /ragemode.jsp at line 39"


 
Amit Ghorpade
Bartender
Posts: 2854
10
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
WeiJie Lim wrote:Okay I modified the code.. now the code looks better now

Honestly, it is not much improved yet.

WeiJie Lim wrote:"org.apache.jasper.JasperException: An exception occurred processing JSP page /ragemode.jsp at line 39"

You need to read the stacktrace to find the root cause of the exception.
Does your assignment require you to submit the form to the same JSP? I am not getting the purpose behind this.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic