File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Spring and the fly likes spring jdbc and action class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "spring jdbc and action class" Watch "spring jdbc and action class" New topic
Author

spring jdbc and action class

manjiri chunekar
Greenhorn

Joined: Apr 08, 2011
Posts: 13


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..
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3775

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.


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
manjiri chunekar
Greenhorn

Joined: Apr 08, 2011
Posts: 13
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

Joined: Mar 24, 2008
Posts: 3775

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

Joined: Apr 08, 2011
Posts: 13
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....

Prasad Krishnegowda
Ranch Hand

Joined: Apr 25, 2010
Posts: 507

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.


Regards, Prasad
SCJP 5 (93%)
manjiri chunekar
Greenhorn

Joined: Apr 08, 2011
Posts: 13
CustomerAction






CustomerDAO





index.jsp



Customer





Prasad Krishnegowda
Ranch Hand

Joined: Apr 25, 2010
Posts: 507

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..
Josh Long
author
Greenhorn

Joined: Apr 04, 2011
Posts: 24

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.


Thanks, Josh Long
Spring Developer Advocate, SpringSource, a division of VMware
http://blog.springsource.org - http://www.joshlong.com
Josh Long
author
Greenhorn

Joined: Apr 04, 2011
Posts: 24

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

Joined: Apr 08, 2011
Posts: 13
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: spring jdbc and action class
 
Similar Threads
Sharing of Persistence Context - Multiple WAR
Spring
Benefits of Using Spring and Struts
K&B pg 359: No of string objects?
dwr autosuggestion and autocomplete