Yusuf ElSaadi

Greenhorn
+ Follow
since Jun 30, 2016
Yusuf likes ...
Eclipse IDE Firefox Browser Java
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
4
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Yusuf ElSaadi

Okay, so it turns out I was being dumb and didn't put in two values in the parentheses there... Oops. Thank you Dave!
Here's what it looks like, apologies for not including it in the previous post.

I had some values taking up one column and few rows before, but I still had the same error, so I feel like that might not be the issue, though.
Thank you, I didn't understand how PreparedStatement worked or what it was used for really, so that was pretty helpful and helped me solve the issues there. I'm running into another SQLException, though, and it's making me question whether my program is really connected to my SQL database.

Now, when I try to run the program, it gets messed up at
, which I changed from executeQuery since I'm trying to do an INSERT INTO operation.

Here is my new HelloWorldAction.java:


Here's the error I'm running into. For context, my compliments table is empty since I want it to only be populated with entries entered. When it comes to showing stacktraces, am I supposed to put this in the \[code\] brackets?:

Struts Problem Report
Struts has detected an unhandled exception:

Messages: Column count doesn't match value count at row 1

File: com/mysql/jdbc/SQLError.java
Line number: 963


--------------------------------------------------------------------------------

Stacktraces
java.sql.SQLException: Column count doesn't match value count at row 1
    com.mysql.jdbc.SQLError.createSQLException(SQLError.java:963)
    com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3966)
    com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3902)
    com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2526)
    com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2673)
    com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2549)
    com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1861)
    com.mysql.jdbc.PreparedStatement.executeUpdateInternal(PreparedStatement.java:2073)
    com.mysql.jdbc.PreparedStatement.executeUpdateInternal(PreparedStatement.java:2009)
    com.mysql.jdbc.PreparedStatement.executeLargeUpdate(PreparedStatement.java:5098)
    com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1994)
    com.tutorialspoint.struts2.HelloWorldAction.execute(HelloWorldAction.java:39)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    java.lang.reflect.Method.invoke(Unknown Source)
    ognl.OgnlRuntime.invokeMethod(OgnlRuntime.java:871)
    ognl.OgnlRuntime.callAppropriateMethod(OgnlRuntime.java:1537)
    ognl.ObjectMethodAccessor.callMethod(ObjectMethodAccessor.java:68)
    com.opensymphony.xwork2.ognl.accessor.XWorkMethodAccessor.callMethodWithDebugInfo(XWorkMethodAccessor.java:96)
    com.opensymphony.xwork2.ognl.accessor.XWorkMethodAccessor.callMethod(XWorkMethodAccessor.java:88)
    ognl.OgnlRuntime.callMethod(OgnlRuntime.java:1613)
    ognl.ASTMethod.getValueBody(ASTMethod.java:91)
    ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:212)
    ognl.SimpleNode.getValue(SimpleNode.java:258)
    ognl.Ognl.getValue(Ognl.java:494)
    ognl.Ognl.getValue(Ognl.java:458)
    com.opensymphony.xwork2.ognl.OgnlUtil$3.execute(OgnlUtil.java:351)
    com.opensymphony.xwork2.ognl.OgnlUtil.compileAndExecuteMethod(OgnlUtil.java:403)
    com.opensymphony.xwork2.ognl.OgnlUtil.callMethod(OgnlUtil.java:349)
    com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:422)
    com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:284)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:245)
    org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:252)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:240)
    com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:176)
    com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:97)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:240)
    com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:260)
    org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:69)
    com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:97)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:240)
    com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:133)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:240)
    com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:133)
    com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:97)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:240)
    com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:133)
    com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:97)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:240)
    com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:188)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:240)
    org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:73)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:240)
    org.apache.struts2.interceptor.DateTextFieldInterceptor.intercept(DateTextFieldInterceptor.java:120)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:240)
    org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:91)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:240)
    org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:244)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:240)
    com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:99)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:240)
    com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:139)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:240)
    com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:155)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:240)
    com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:174)
    com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:97)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:240)
    com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:130)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:240)
    org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:240)
    com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:193)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:240)
    com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:193)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:240)
    org.apache.struts2.factory.StrutsActionProxy.execute(StrutsActionProxy.java:54)
    org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:556)
    org.apache.struts2.dispatcher.ExecuteOperations.executeAction(ExecuteOperations.java:81)
    org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:113)
    org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
    org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
    org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
    org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
    org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
    org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
    org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
    java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    java.lang.Thread.run(Unknown Source)

Hi guys,

Thank you. I would have responded earlier but SQL was being a pain to get working. Anyway, here's the error message:

Struts Problem Report
Struts has detected an unhandled exception:

Messages: Parameter index out of range (1 > number of parameters, which is 0).

File: com/mysql/jdbc/SQLError.java
Line number: 963


--------------------------------------------------------------------------------

Stacktraces
java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0).
    com.mysql.jdbc.SQLError.createSQLException(SQLError.java:963)
    com.mysql.jdbc.SQLError.createSQLException(SQLError.java:896)
    com.mysql.jdbc.SQLError.createSQLException(SQLError.java:885)
    com.mysql.jdbc.SQLError.createSQLException(SQLError.java:860)
    com.mysql.jdbc.PreparedStatement.checkBounds(PreparedStatement.java:3321)
    com.mysql.jdbc.PreparedStatement.setInternal(PreparedStatement.java:3306)
    com.mysql.jdbc.PreparedStatement.setString(PreparedStatement.java:4021)
    com.tutorialspoint.struts2.HelloWorldAction.execute(HelloWorldAction.java:37)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    java.lang.reflect.Method.invoke(Unknown Source)
    ognl.OgnlRuntime.invokeMethod(OgnlRuntime.java:892)
    ognl.OgnlRuntime.callAppropriateMethod(OgnlRuntime.java:1537)
    ognl.ObjectMethodAccessor.callMethod(ObjectMethodAccessor.java:68)
    com.opensymphony.xwork2.ognl.accessor.XWorkMethodAccessor.callMethodWithDebugInfo(XWorkMethodAccessor.java:96)
    com.opensymphony.xwork2.ognl.accessor.XWorkMethodAccessor.callMethod(XWorkMethodAccessor.java:88)
    ognl.OgnlRuntime.callMethod(OgnlRuntime.java:1613)
    ognl.ASTMethod.getValueBody(ASTMethod.java:91)
    ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:212)
    ognl.SimpleNode.getValue(SimpleNode.java:258)
    ognl.Ognl.getValue(Ognl.java:494)
    ognl.Ognl.getValue(Ognl.java:458)
    com.opensymphony.xwork2.ognl.OgnlUtil$3.execute(OgnlUtil.java:351)
    com.opensymphony.xwork2.ognl.OgnlUtil.compileAndExecuteMethod(OgnlUtil.java:403)
    com.opensymphony.xwork2.ognl.OgnlUtil.callMethod(OgnlUtil.java:349)
    com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:422)
    com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:284)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:245)
    org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:252)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:240)
    com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:176)
    com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:97)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:240)
    com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:260)
    org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:69)
    com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:97)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:240)
    com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:133)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:240)
    com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:133)
    com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:97)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:240)
    com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:133)
    com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:97)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:240)
    com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:188)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:240)
    org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:73)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:240)
    org.apache.struts2.interceptor.DateTextFieldInterceptor.intercept(DateTextFieldInterceptor.java:120)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:240)
    org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:91)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:240)
    org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:244)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:240)
    com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:99)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:240)
    com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:139)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:240)
    com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:155)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:240)
    com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:174)
    com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:97)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:240)
    com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:130)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:240)
    org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:240)
    com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:193)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:240)
    com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:193)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:240)
    org.apache.struts2.factory.StrutsActionProxy.execute(StrutsActionProxy.java:54)
    org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:556)
    org.apache.struts2.dispatcher.ExecuteOperations.executeAction(ExecuteOperations.java:81)
    org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:113)
    org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
    org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
    org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
    org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
    org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
    org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
    org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
    java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    java.lang.Thread.run(Unknown Source)
   
Hello! I'm new to the Code Ranch, but I've lurked around here a little. I have a couple of years' experience with Java, but SQL/Struts2/HTML/Servlets/WEBSTUFFINGENERAL is all very new to me. I tried searching for the issue I'm having but it either isn't in here or I'm really awful at searching issues... probably the latter. I apologize in advance if I don't do a great job of explaining my issue and/or flood the page with code.

Anyway, I'm trying to make a Struts application in Eclipse that works with a table in a database I have on MySQL. What I want it to do is allow a user to submit what they think about something, and then display everything that has been entered in the past. I guess it works somewhat like a comment section.

To better illustrate what I mean: Someone submits saying that the cat on the index page is "cute." On the resultant page, it should display only "cute" since they are the first to state anything. They go back to the index page and submit that the cat is "totally rad." On the resultant page, it should display "cute" followed by "totally rad" on the next line.

I've been basing my execute() function off of this tutorial, but it doesn't seem like it covers inserting data, so I modified it. I think this could be the main issue. I'm not 100% sure what I'm doing or what's going on in some of the lines.

I've narrowed down where the issue is, but I'm not sure how to fix it. In short, my  main issue is in my HelloWorldAction.java, with the statement "ps.setString(1, newCompliment);"

Also, I apologize for the poor file names. I didn't want to mess things up just because I had filenames wrong, so I kept them in line with what I had in previous Struts2 tutorials.

Here is my file structure:


Files:
HelloWorldAction.java



struts.xml:


web.xml:


AccessDenied.jsp:


HelloWorld.jsp - This is the intended result. I want it to print out the ArrayList<String> of previous responses.


index.jsp:


For learning MySQL, I've been using this site along with the sample database they provided. In that sample database, I made a new table called "compliments" to be used in the above application.


Thank you so so much in advance for any and all help!!!

2 years ago