Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Having issues with inserting Strings into a database from Struts - Using Eclipse & MySQL

 
Yusuf ElSaadi
Greenhorn
Posts: 5
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!!!

 
Joe Ess
Bartender
Posts: 9339
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the JavaRanch!
When you catch an exception, it's always a good idea to print out the exception message and the stack trace.  The message will tell you why the exception occurred and the stack trace will tell you where.  Try it and let us know what results you get.
 
Paul Clapham
Sheriff
Posts: 21576
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't see the relevance of Struts to this question, in fact it looks like a plain old JDBC problem as far as I can see. So I've added the post to the JDBC forum.
 
Yusuf ElSaadi
Greenhorn
Posts: 5
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)
   
 
Joe Ess
Bartender
Posts: 9339
10
Linux Mac OS X Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So the error message says:
Messages: Parameter index out of range (1 > number of parameters, which is 0).


Looking at the SQL you are using:
String sql = "INSERT INTO compliments(compliment) values(newCompliment);";


I'd say that's the case.  Take a quick look at The Java Tutorial: Using Prepared Statements and let us know if that helps.
 
Yusuf ElSaadi
Greenhorn
Posts: 5
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)

 
Dave Tolls
Ranch Hand
Posts: 2106
15
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What does the compliments table look like?

Is it just the one column?
 
Yusuf ElSaadi
Greenhorn
Posts: 5
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Dave Tolls
Ranch Hand
Posts: 2106
15
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, your SQL looks like:
INSERT INTO compliments values(?);

So I'm not sure how MySQL would handle the lack of data...you have two columns.

I will say that you should remove that ';'.
 
Marsoni Hutao
Greenhorn
Posts: 22
1
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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

In your table, there are 2 columns (id, item_no), and you are inserting only one value. Is the other a primary key? if so, you are missing the basic thumb rule of PK,

Should be unique and not null
.

But here you are not inserting second or first value to DB, which means it will be taking a null.
 
Yusuf ElSaadi
Greenhorn
Posts: 5
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay, so it turns out I was being dumb and didn't put in two values in the parentheses there... Oops. Thank you Dave!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic