CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   Java and JSP (http://www.codingforums.com/forumdisplay.php?f=54)
-   -   java.sql.SQLException: Could not set SQL query (http://www.codingforums.com/showthread.php?t=274548)

shunaqie_89 09-28-2012 10:42 AM

java.sql.SQLException: Could not set SQL query
 
Hi,

I have a problem wit setSQL.
My coding like below,

PHP Code:

try {
                    
sql "SELECT " COLUMN_1 COLUMN_2 COLUMN_3 COLUMN_4;
                    
sql2 " FROM " PARAM_TABLE " ORDER BY " COLUMN_1 COLUMN_2;

                    
sqlUtil.setSQL(sql+sql2);

                    
DefaultLogger.debug(this'\n'+"SQL String-> " sql +'\n'sql2);
            }
            catch (
SQLException e) {
                
e.printStackTrace();
            throw new 
SQLException("Could not set SQL query");
            } 



and get error like below,
Code:

Exception =
java.sql.SQLException: Could not set SQL query
        at com.bkr.retail.app.common.ParamDAO.getParameterList(ParamDAO.java:66)
        at com.bkr.retail.ui.common.ParamManager.getParameterData(ParamManager.java:43)
        at com.bkr.retail.ui.common.ParamManager.<init>(ParamManager.java:29)
        at com.bkr.retail.ui.common.ParamHelper.getInstance(ParamHelper.java:22)
        at com.bkr.retail.ui.financing.FinancingEligibilityCheckPersonalLoanFormValidator.validateInput(FinancingEligibilityCheckPersonalLoanFormValidator.java:110)
        at com.bkr.retail.ui.financing.FinancingEligibilityCheckPersonalLoanAction.validateInput(FinancingEligibilityCheckPersonalLoanAction.java:167)
        at com.bkr.retail.ui.common.framework.CommonAction.perform(CommonAction.java:260)
        at org.apache.struts.action.ActionServlet.processActionPerform(ActionServlet.java:1720)
        at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1519)
        at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:505)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
        at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:1006)
        at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:419)
        at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:315)
        at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:6722)
        at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
        at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121)
        at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:3764)
        at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2644)
        at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:219)
        at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:178)


Can anyone help me with this problem? Really have no idea why.
I'm using j2sdk1.4.2_05..

Fou-Lu 09-29-2012 05:55 PM

There's simply not enough information here. What does the sqlUtil.setSql do?
You should move the DefaultLogger call up as well; if the sqlUtil tosses the exception (which it appears to), the logger cannot issue a .debug call since it will never make it there. But knowing what that sql string it created is would be handy.

Trollypolly 09-30-2012 04:41 PM

If you are trying to pull information from your database there are a couple of ways of doing this. You can do:

Code:


String sql = "SELECT " + select +
                            " FROM " + from +
                            " JOIN " + join +
                            " ON " + on1 + " = " + on2 +
                            " WHERE " + where +
                    " ORDER BY " + order;
           
            Cursor mCur = mDb.rawQuery(sql, null);

You can add/remove any SQL commands from my code and it should work. You will be returned a cursor which you will need to know how to gather information from aswell.

Another way of pulling information from your database is:

Code:


String table = "insertTableNameHere";  //Table name goes here
String[] = {"column1", "column2"}  //any columns you need to put, place here.

Cursor cursor = mDb.query(tableName, column, null, null, null, null, null);

If you have any questions feel free to ask.


All times are GMT +1. The time now is 06:13 AM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.