• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

spring jdbc and action class

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


i m doing assignments on struts and spring...
i created db in ms access and DSN id myDSN...
created 3 buttons delete,create, update
created 3 text box: cust_id, cust_fname, cust_lname...
applicationConfig.xml
struts-config.xml
Cust is form bean
CustomerDAo
CustomerAction

what can i do... i m trying.... but not success yet... HELP ME..
 
Bartender
Posts: 4116
72
Mac TypeScript Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to JavaRanch, Manjiri Chunekar

Please don't duplicate posts (duplicate) in the forum.
Spring and Struts both are web frameworks. You may use some features from Spring and some from Struts in the same application, but that's very unlikely. But if you are a beginner to both of these you may start with the getting started guide provided by both frameworks. I suggest not to go for DAO implementations etc... at the beginning.
 
manjiri chunekar
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks.....
ok... i wont duplicate post again..
will take care of that....
i done small assignments on struts, spring.... like struts-dispatch,bean etc. AND spring injection,little bit on spring MVC, spring jdbc...
So, i m trying this.....
 
Vijitha Kumara
Bartender
Posts: 4116
72
Mac TypeScript Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok. Then please post some specific questions/issues you are having probably with some code which would help others to help you.
 
manjiri chunekar
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
exception

javax.servlet.ServletException: org.springframework.jdbc.BadSqlGrammarException: StatementCallback; bad SQL grammar [INSERT INTO Cust (Cust_Id, Cust_Fname, Cust_Lname) VALUES (?, ?, ?)]; nested exception is java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver]COUNT field incorrect
org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:286)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)
javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)


root cause

org.springframework.jdbc.BadSqlGrammarException: StatementCallback; bad SQL grammar [INSERT INTO Cust (Cust_Id, Cust_Fname, Cust_Lname) VALUES (?, ?, ?)]; nested exception is java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver]COUNT field incorrect
org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.translate(SQLStateSQLExceptionTranslator.java:111)
org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.translate(SQLErrorCodeSQLExceptionTranslator.java:322)
org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:407)
org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:458)
org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:466)
org.springframework.jdbc.core.JdbcTemplate.queryForList(JdbcTemplate.java:497)
com.CustomerDAO.Add(CustomerDAO.java:29)
com.CustomerAction.create(CustomerAction.java:86)
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)
org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:269)
org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:170)
org.apache.struts.chain.commands.servlet.ExecuteAction.execute(ExecuteAction.java:58)
org.apache.struts.chain.commands.AbstractExecuteAction.execute(AbstractExecuteAction.java:67)
org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51)
org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191)
org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:305)
org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191)
org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)
javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)


root cause

java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver]COUNT field incorrect
sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source)
sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source)
sun.jdbc.odbc.JdbcOdbc.SQLExecDirect(Unknown Source)
sun.jdbc.odbc.JdbcOdbcStatement.execute(Unknown Source)
sun.jdbc.odbc.JdbcOdbcStatement.executeQuery(Unknown Source)
org.springframework.jdbc.core.JdbcTemplate$1QueryStatementCallback.doInStatement(JdbcTemplate.java:443)
org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:396)
org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:458)
org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:466)
org.springframework.jdbc.core.JdbcTemplate.queryForList(JdbcTemplate.java:497)
com.CustomerDAO.Add(CustomerDAO.java:29)
com.CustomerAction.create(CustomerAction.java:86)
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)
org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:269)
org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:170)
org.apache.struts.chain.commands.servlet.ExecuteAction.execute(ExecuteAction.java:58)
org.apache.struts.chain.commands.AbstractExecuteAction.execute(AbstractExecuteAction.java:67)
org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51)
org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191)
org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:305)
org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191)
org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)
javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)



My db is in ms-access
DSN is myDSN

Help me....

 
Ranch Hand
Posts: 672
4
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ca you show us your code, so we can see what query you are using to insert into database and help you better, also let us know the data types of your columns in the database.
 
manjiri chunekar
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
CustomerAction






CustomerDAO





index.jsp



Customer





 
Prasad Krishnegowda
Ranch Hand
Posts: 672
4
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Where are you setting the values for the '?' in the query..
Please edit your post and use code tags, codes which are not formatted are very difficult to read..
 
author
Posts: 24
5
Spring Tomcat Server Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

First, I'd ensure that your query is correct. I note that in the INSERT statement you ran a queryForList which won't have the result you're expecting. Try using JdbcTemplate#execute* and so on instead for operations that aren't expected to return a result (except, perhaps, the keys that were updated or generated as a side effect). As the previos commenter noted, you should also provide query parameters: e.g., "UPDATE FOO SET a =?, b = ? " would only work if you ran a jdbcTemplate call that specified values for the positional parameters (the parts with "?"), like this:


Also, to help narrow this problem down, ensure that you've got a java.sql.DataSource configured and then a JdbcTemplate and try runninng the operations seperately, in a public static void main(){ } block or unit test. This will help you identify problems with your logic, and *then* you can integrate into your struts code as you have here.
 
Josh X Long
author
Posts: 24
5
Spring Tomcat Server Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
BTW, my book 'Spring Recipes, 2nd Edition' has lots of good information on this kind of stuff. If you don't want a book, SpringSource has published a lot of content specifically geared to getting started with Spring. See http://blog.springsource.com/category/green-beans/ for a list of blogs that are dedicated to taking the first steps with things including data access. To learn more, see the blog post http://blog.springsource.com/2011/01/07/green-beans-getting-started-with-spring-in-your-service-tier/. There's also corresponding sample code that you're free to download and examine.
 
manjiri chunekar
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thaks for giving me links..
yet I am not succeed..
please help me
its giving still same error

whats wrong in my syntax???

javax.servlet.ServletException: StatementCallback; bad SQL grammar [INSERT INTO Cust (Cust_Id, Cust_Fname, Cust_Lname) VALUES (?,?,?)]; nested exception is java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver]COUNT field incorrect

db in ms access
 
If you two don't stop this rough-housing somebody is going to end up crying. Sit down and read this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic