Building an SQL string

Hi, I have run into a problem where i'm not sure how to start. I'm generating reports based on what criteria a user chooses. Here is a list of variables that are possible criteria.
String rep     
String callType
String action           String phone
String name
String startDate
String endDate
String endTime
String startTime
All the following variables are populated based on user input. The reports give information on calls taken by Internet HelpDesk staff. For example, lets say a manager wants to see "all calls that were created by a representative with the name of "ANDY" that was created on the date of 10/13/2001. This means that rep = "Andy"; and startDate = "10/13/2001;, and that all other variables are null or empty strings. After checking all variables, the SQL statment should look something like "SELECT (table fields) FROM (tables) WHERE Representative ='"+rep+"' and Date = '"+startDate+"'"
My problem is building that sql string because it can be so many different things. If all variables are null, Then there should be no 'WHERE' and no quotes anywhere just "SELECT (table fields) FROM (tables)" you see what i mean
I'm not sure what the best way to approch this is. I'm pretty sure i can do it with some crazy if statements but am also more sure that thats not the best way to do it.
Any suggestions on how to approch this?
Thanks in advance

I don't think you/anybody could find a better way to
do that because you have so many possible criteria.
How do you know you are more sure there is the "best
way" to do that? If you are sure, how to do that?
Never mind if you are not sure. :-)Thanks jrodi

Similar Messages

  • Building the SQL string

    Hi, i stumbled over the following while developing my application. As we all know, it's not a good idea to do the following
    String sql = "insert into mytable values ('";
    sql += object.getStringValue1() + "','";
    sql += object.getStringValue2() + "','";
    // more...instead we should do it like this
    StringBuffer sql = "insert into mytable values ('";
    sql.append(object.getStringValue1()).append("',");
    sql.append(object.getStringValue2()).append("',");
    // more...If you agree so far, my question now: on how many appends is it worth the effort? I mean, it's clear to me, that i would use StringBuffer when appending many strings. But should i use StringBuffer to append two strings? Three strings?
    Has anybody come up with some experience in this field?
    Thanks in advance for your comments.
    Markus

    For me it's not worth the effort to do either of those things. Instead, I use this:String sql = "insert into mytable values (?,?,?,?,?)";
    PreparedStatement ps = conn.prepareStatement(sql);and later in the program:ps.setString(1, object.getStringValue1());
    ps.setString(2, object.getStringValue2());
    // more...
    ps.executeQuery();You only have to create the PreparedStatement once and you can reuse it as often as you like. Don't close it until you don't need to use it any more.

  • Building SQL String ?

    I am trying to build a SQL String and send it to the database...
    this is how i am trying to form a query string
    StringBuffer sBuff = new StringBuffer(250);
    sBuff.append("old information")
    sBuff.append("new history added twice");
    String caseObjId = "2567034";
    StringBuffer queryBuff = new StringBuffer(250);
    queryBuff.append("UPDATE table_case ");
    queryBuff.append("SET case_history =" + sBuff);
    queryBuff.append("WHERE objid =" + caseObjId);
    i am getting SQL Exception saying
    com.sybase.jdbc2.jdbc.SybSQLException: Incorrect syntax near 'information'.
    let me know what where i am doing mistake
    thanks
    KM

    The previous posters are right on target for debugging your problem; if you printed out the query that's giving you problems, you would see:
    UPDATE table_case
    SET case_history =old informationnew history added twice
    WHERE objid =2567034 and the problem then becomes obvious that the string/varchar data needs to be quoted.
    That will fix your immediate problem.
    However, since you are obviously a newbie, I'll tell you how to fix 2 or 3 more problems; don't use Statement, use PreparedStatement and bind your parameter values.
    <rant>
    First, when a database executes a SQL statement for the first time, it has to "parse" it. "parsing" is an awful like compiling in that it often takes 100 times longer or more to compile a bit of code than it does to execute it. A good database will check a cache of parsed SQL to see if it doesn't need to parse again, but it often relies on an exact match of the SQL. If you use Statement and change the value of case_history or objid, it's not an exact match. However, if you use PreparedStatements, your values aren't part of the SQL; therefore you get a lot more matches in the parse cache and the database saves a huge amount of work.
    Second, when you build up SQL with embedded values like you're doing, you have to deal with any special characters appropriately; in particular the single quote character; for example, if you have a LAST_NAME column, you need to support the name "O'Conner"; the single-quote in the middle has to be recognized and properly escaped. This problem simply goes away with parameter bindings; the code and the data are widely seperated and there's no question where the boundary is.
    Third, building up SQL in the way you did is the technique that causes a major security hole an poorly coded applications. Let's say you're building an e-commerce site that will keep customer credit card numbers on file (risky) and want a function to display credit card numbers given an account number (not really a good idea, but it illustrates the technique). You have code like:
    StringBuffer queryBuff = new StringBuffer();
    queryBuff.append("SELECT CC_FIRST_NAME, CC_LAST_NAME, CC_NUMBER, CC_EXP ");
    queryBuff.append("FROM CARD_DATA);
    queryBuff.append("WHERE account_number  =" + acct_number);this will work just great when a user enters their account number of "1234567", and it will work just great (for the hacker) when the account number is entered as "1234567 or (CC_FIRST_NAME = 'Bill' and CC_LAST_NAME = 'Gates')"; the hacker's add-ons are treated as code, not data, and the e-commerce site spits up a customer's data to an authorized person. Again, parameter binding prevents this and add-ons get treated as part of the account number, probably generating a data-type error on the database. Obviously, you can validate the data to numerics in this example, but if you use PreparedStatement instead, you don't have to think, it takes care of itself.
    </rant>

  • Hard coded SQL string doesn't run with error PLS-00103

    I have created a package with 34 stored procedures [pre]to create some materialized view with hard coded SQL [pre]string (client required for this hard coding). The [pre]first part with 21 simple create statements has
    [pre]worked fine. 2nd part with 11 complicated create [pre]statements, only first one has worked. all others [pre]have  not worked.
    [pre]
    I used dbms_output.put_line (sql_string) to check the [pre]individual create statement, it has looked fine. I [pre]have run individual SP within package. I have got [pre]error message as ORA-06550: line 1, column 45:
    [pre]PLS-00103: Encountered the symbol "end-of-file" when [pre]expecting one of the following: ; [pre]
    <an identifier> <a double-quoted delimited-identifier> [pre]The symbol ";" was substituted for "end-of-file" to [pre]continue.
    [pre]I have checked SQL string between 1st part and 2nd [pre]part. They are the same and all with ';' to end SQL [pre]string and END SP name in the end. Please help me to [pre]identify where the problems are. Thanks. Followings [pre]are some sample SQL string:
    [pre]PROCEDURE sp_1st_string
    [pre]IS
    [pre]BEGIN
    [pre]    EXECUTE IMMEDIATE 'CREATE MATERIALIZED VIEW
    [pre]mv_name1 TABLESPACE space_name PARALLEL ( DEGREE [pre]DEFAULT INSTANCES DEFAULT ) BUILD IMMEDIATE REFRESH [pre]COMPLETE ON DEMAND WITH PRIMARY KEY AS SELECT col1, [pre]col2,col3, col4, col5 FROM tableone A, table_two B [pre]WHERE A.id = B.id';
    [pre]COMMIT;
    [pre]END sp_1st_string;
    [pre]PROCEDURE sp_2nd_string
    [pre]IS
    [pre]BEGIN
    [pre]   EXECUTE IMMEDIATE ' CREATE MATERIALIZED VIEW
    [pre]mv_name2 TABLESPACE PDE_DATA PARALLEL ( DEGREE [pre]DEFAULT INSTANCES DEFAULT ) BUILD IMMEDIATE REFRESH [pre]COMPLETE ON DEMAND WITH PRIMARY KEY AS select col1 .. [pre]col10 from tableone a, tabletwo b, tablethree c, [pre]tablefour d, tablefive e, tablesix f where clause;
    [pre]COMMIT;
    [pre]END sp_2nd_string;
    Message was edited by:
            citicbj
    Message was edited by:
            citicbj                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    stevencallan:
    Thanks for your advice. I have been thinking the above problem may be [pre]caused by this. If I run 'Create MV statement' in SQL PLUS or Toad, single quote [pre]will work. But when I put hard coded SQL string in package and stored [pre]procedure, it will cause compiling error. After I took off single quote, SP will be [pre][pre]compiled successfully. When I run package.sp, it will cause the problem. [pre]Here is the sample code:[pre]
    [pre]CREATE MATERIALIZED VIEW my_mv TABLESPACE space_name [pre][pre]PARALLEL (DEGREE DEFAULT INSTANCES DEFAULT) BUILD IMMEDIATE [pre]REFRESH COMPLETE ON DEMAND WITH PRIMARY KEY AS select A.ID , [pre]A.CNTL_NUM, C.XX_CODE, D.FIRST_NAME, D.MDL_NAME, [pre]D.LAST_NAME, H.XX_DESC, TO_DATE(TO_CHAR(C.CREAT_TS, [pre]'MM/DD/YYYY'),'MM/DD/YY'), F.STATE, CASE WHEN A.XX_CODE IS NOT NULL [pre]THEN X END, E.X_DESC  from TABLE1 A, TABLE2 B, TABLE3 C, TABLE4 [pre]D, TABLE5 E, TABLE6 F, TABLE7 G, TABLE8 H
    [pre]where D.X_SW = 'X' and B.X_SW = X' and G.X_SW = 'X' and B.CNTL_ID = [pre]A.CNTL_ID and B.CNTL_ID = D.CNTL_ID and B.X_ID = C.X_ID and B.X_ID = [pre]G.X_ID and B.X_ID = F.X_ID and G.X_CD = H.X_CD and B.X_CD = E.X_CD [pre]and E.X_CD = '25' and C.ENRLMT_ID NOT LIKE 'O%'; [pre]
    [pre]When I hard coded this statement in package and sp, I have to take off single [pre]quote ' ' form 'MM/DD/YYYY', 'MM/DD/YY', X_SW ='X', X_CD = '25' AND NOT [pre]LIKE 'O%', Then I can compile whole package successfully. This is why I [pre]mentioned that 1st part 21 simple create statement work because they don't have [pre]these single quote in the statement. In 2nd part with 13 complicated create [pre]statements, some of them have no single quote in the statement. They will [pre]run. Some of them with single quote in statement. They will have the problem [pre]to run if I take off single for compiling. [pre]
    [pre]Please give me some idea what is the reason. Thanks a lot.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • SQL string for blank or populated date

    I need to build an Oracle sql string where I need to check that if a datetime column is not blank its value must be greater than current_date and I am failing.
    SELECT ColumnData FROM MyTable WHERE STARTDATE > current_date AND (ENDDATE !="" and ENDATE > current_date) Please tell me how I should do this.
    Edited by: StrayGrey on May 15, 2009 1:09 PM

    SELECT ColumnData FROM MyTable WHERE STARTDATE > current_date AND ENDATE > current_date

  • Adding " char to SQL string

    I'm using Netbeans IDE 3.4 and trying to build SQL statments for MySQL DB.
    For that reason I need to concate the char " or ' to my SQL string . for example I need to create the string:
    SELECT * FROM user WHERE username = "test".
    I use variables to get the username from other function and I need to create that statment, I tried to run the following code:
    SELECT * FROM user WHERE username =" + '\"' + Username + '\"'
    and also tried to run:
    SELECT * FROM user WHERE username =" + "\"" + Username + "\""
    but I get always the following string:
    SELECT * FROM user WHERE username =\"test\" , which of course is not OK.
    I tried to replace the " with ' but with no luck.
    Can someone help ?
    Many Thanks...

    String sql = "SELECT * FROM user WHERE username = '" + username + "'"
    single/double double/single/double
    You will have problems where your username is something like 'O'Neil' where you will have to escape the single quote within the username by adding an additional single quote 'O''Neil'
    single/single

  • TOPLINK-4002 SQL string is not Query Error Code: 17128

    I got following exception when trying to execute native SQL query via session EJB. The query is defined in orm.xml file using JDev 11g Preview:
    javax.ejb.EJBException: Exception [TOPLINK-4002] (Oracle TopLink - 11g Release 1 (11.1.1.0.0) (Build 070502)): oracle.toplink.exceptions.DatabaseException
    Internal Exception: java.sql.SQLException: SQL string is not QueryError Code: 17128
    Call:findProfilesByLastName
    I have following native query defined:
    select o.last_name,
    o.first_name,
    o.middle_name,
    o.birth_date,
    o.sex_code,
    a.height_cm,
    a.weight_kg,
    o.PERSON_ID
    from persons o,
    person_bookings b,
    person_physical_attributes a
    where o.PERSON_ID = b.PERSON_ID
    and b.PERSON_BOOK_ID = a.PERSON_BOOK_ID
    and o.last_name like '%?1%'
    I also tried these versions of the same query but got the same exception:
    select o.last_name,
    o.first_name,
    o.middle_name,
    o.birth_date,
    o.sex_code,
    a.height_cm,
    a.weight_kg,
    o.PERSON_ID
    from persons o,
    person_bookings b,
    person_physical_attributes a
    where o.PERSON_ID = b.PERSON_ID
    and b.PERSON_BOOK_ID = a.PERSON_BOOK_ID
    and o.last_name like '%:1%'
    select o.last_name,
    o.first_name,
    o.middle_name,
    o.birth_date,
    o.sex_code,
    a.height_cm,
    a.weight_kg,
    o.PERSON_ID
    from persons o,
    person_bookings b,
    person_physical_attributes a
    where o.PERSON_ID = b.PERSON_ID
    and b.PERSON_BOOK_ID = a.PERSON_BOOK_ID
    and o.last_name like '%#partialName%'
    select o.last_name,
    o.first_name,
    o.middle_name,
    o.birth_date,
    o.sex_code,
    a.height_cm,
    a.weight_kg,
    o.PERSON_ID
    from persons o,
    person_bookings b,
    person_physical_attributes a
    where o.PERSON_ID = b.PERSON_ID
    and b.PERSON_BOOK_ID = a.PERSON_BOOK_ID
    and o.last_name like '%#partialName#%'
    Log trace:
    Query:DataReadQuery(); nested exception is:
    Exception [TOPLINK-4002] (Oracle TopLink - 11g Release 1 (11.1.1.0.0) (Build 070502)): oracle.toplink.exceptions.DatabaseException
    Internal Exception: java.sql.SQLException: SQL string is not QueryError Code: 17128
    Call:findProfilesByLastName
    Query:DataReadQuery(); nested exception is: oracle.oc4j.rmi.OracleRemoteException: Exception [TOPLINK-4002] (Oracle TopLink - 11g Release 1 (11.1.1.0.0) (Build 070502)): oracle.toplink.exceptions.DatabaseException
    Internal Exception: java.sql.SQLException: SQL string is not QueryError Code: 17128
    Call:findProfilesByLastName
    Query:DataReadQuery(); nested exception is:
    Exception [TOPLINK-4002] (Oracle TopLink - 11g Release 1 (11.1.1.0.0) (Build 070502)): oracle.toplink.exceptions.DatabaseException
    Internal Exception: java.sql.SQLException: SQL string is not QueryError Code: 17128
    oracle.oc4j.rmi.OracleRemoteException: Exception [TOPLINK-4002] (Oracle TopLink - 11g Release 1 (11.1.1.0.0) (Build 070502)): oracle.toplink.exceptions.DatabaseException
    Internal Exception: java.sql.SQLException: SQL string is not QueryError Code: 17128
    Call:findProfilesByLastName
    Query:DataReadQuery()
    at com.evermind.server.ejb.EJBUtils.getUserException(EJBUtils.java:127)
    at com.evermind.server.ejb.interceptor.system.AbstractTxInterceptor.convertAndHandleMethodException(AbstractTxInterceptor.java:91)
    at com.evermind.server.ejb.interceptor.system.TxRequiredInterceptor.invoke(TxRequiredInterceptor.java:52)
    at com.evermind.server.ejb.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:101)
    at com.evermind.server.ejb.interceptor.system.JAASInterceptor$1.run(JAASInterceptor.java:52)
    at java.security.AccessController.doPrivileged(Native Method)
    at javax.security.auth.Subject.doAsPrivileged(Subject.java:517)
    at oracle.oc4j.security.SecurityServices.doAsPrivileged(SecurityServices.java:150)
    at oracle.oc4j.security.SecurityServices.doAsPrivileged(SecurityServices.java:420)
    at oracle.oc4j.security.JaasModeImpl$DoAsPrivilegedExecutor.execute(JaasModeImpl.java:280)
    at com.evermind.server.ejb.interceptor.system.JAASInterceptor.invoke(JAASInterceptor.java:57)
    at com.evermind.server.ejb.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:101)
    at com.evermind.server.ejb.interceptor.system.DMSInterceptor.invoke(DMSInterceptor.java:52)
    at com.evermind.server.ejb.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:101)
    at com.evermind.server.ejb.InvocationContextPool.invoke(InvocationContextPool.java:58)
    at com.evermind.server.ejb.StatelessSessionEJBObject.OC4J_invokeMethod(StatelessSessionEJBObject.java:104)
    at SearchFacade_RemoteProxy_43jlpm9.queryProfilesByLastName(Unknown Source)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at com.evermind.server.rmi.RmiMethodCall.invokeMethod(RmiMethodCall.java:104)
    at com.evermind.server.rmi.RmiMethodCall.run(RmiMethodCall.java:59)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:650)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:675)
    at java.lang.Thread.run(Thread.java:595)
    Nested exception is:
    Local Exception Stack:
    Exception [TOPLINK-4002] (Oracle TopLink - 11g Release 1 (11.1.1.0.0) (Build 070502)): oracle.toplink.exceptions.DatabaseException
    Internal Exception: java.sql.SQLException: SQL string is not QueryError Code: 17128
    at oracle.toplink.exceptions.DatabaseException.sqlException(DatabaseException.java:283)
    at oracle.toplink.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:583)
    at oracle.toplink.internal.databaseaccess.DatabaseAccessor.executeCall(DatabaseAccessor.java:443)
    at oracle.toplink.internal.sessions.AbstractSession.executeCall(AbstractSession.java:749)
    at oracle.toplink.internal.queryframework.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:193)
    at oracle.toplink.internal.queryframework.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:179)
    at oracle.toplink.internal.queryframework.DatasourceCallQueryMechanism.executeSelectCall(DatasourceCallQueryMechanism.java:250)
    at oracle.toplink.internal.queryframework.DatasourceCallQueryMechanism.executeSelect(DatasourceCallQueryMechanism.java:232)
    at oracle.toplink.queryframework.DataReadQuery.executeNonCursor(DataReadQuery.java:122)
    at oracle.toplink.queryframework.DataReadQuery.executeDatabaseQuery(DataReadQuery.java:114)
    at oracle.toplink.queryframework.DatabaseQuery.execute(DatabaseQuery.java:671)
    at oracle.toplink.queryframework.DataReadQuery.execute(DataReadQuery.java:100)
    at oracle.toplink.queryframework.DatabaseQuery.executeInUnitOfWork(DatabaseQuery.java:594)
    at oracle.toplink.internal.sessions.UnitOfWorkImpl.internalExecuteQuery(UnitOfWorkImpl.java:2632)
    at oracle.toplink.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1014)
    at oracle.toplink.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:986)
    at oracle.toplink.internal.ejb.cmp3.base.EJBQueryImpl.executeReadQuery(EJBQueryImpl.java:395)
    at oracle.toplink.internal.ejb.cmp3.base.EJBQueryImpl.getResultList(EJBQueryImpl.java:502)
    at ejbmodel.SearchFacadeBean.queryProfilesByLastName(SearchFacadeBean.java:107)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at com.evermind.server.ejb.interceptor.joinpoint.EJBJoinPointImpl.invoke(EJBJoinPointImpl.java:27)
    at com.evermind.server.ejb.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:101)
    at com.evermind.server.ejb.interceptor.system.SetContextActionInterceptor.invoke(SetContextActionInterceptor.java:44)
    at com.evermind.server.ejb.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:101)
    at com.evermind.server.ejb.interceptor.system.DMSInterceptor.invoke(DMSInterceptor.java:52)
    at com.evermind.server.ejb.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:101)
    at com.evermind.server.ejb.interceptor.system.TxRequiredInterceptor.invoke(TxRequiredInterceptor.java:50)
    at com.evermind.server.ejb.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:101)
    at com.evermind.server.ejb.interceptor.system.JAASInterceptor$1.run(JAASInterceptor.java:52)
    at java.security.AccessController.doPrivileged(Native Method)
    at javax.security.auth.Subject.doAsPrivileged(Subject.java:517)
    at oracle.oc4j.security.SecurityServices.doAsPrivileged(SecurityServices.java:150)
    at oracle.oc4j.security.SecurityServices.doAsPrivileged(SecurityServices.java:420)
    at oracle.oc4j.security.JaasModeImpl$DoAsPrivilegedExecutor.execute(JaasModeImpl.java:280)
    at com.evermind.server.ejb.interceptor.system.JAASInterceptor.invoke(JAASInterceptor.java:57)
    at com.evermind.server.ejb.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:101)
    at com.evermind.server.ejb.interceptor.system.DMSInterceptor.invoke(DMSInterceptor.java:52)
    at com.evermind.server.ejb.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:101)
    at com.evermind.server.ejb.InvocationContextPool.invoke(InvocationContextPool.java:58)
    at com.evermind.server.ejb.StatelessSessionEJBObject.OC4J_invokeMethod(StatelessSessionEJBObject.java:104)
    at SearchFacade_RemoteProxy_43jlpm9.queryProfilesByLastName(Unknown Source)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at com.evermind.server.rmi.RmiMethodCall.invokeMethod(RmiMethodCall.java:104)
    at com.evermind.server.rmi.RmiMethodCall.run(RmiMethodCall.java:59)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:650)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:675)
    at java.lang.Thread.run(Thread.java:595)
    Caused by: java.sql.SQLException: SQL string is not Query
    at oracle.jdbc.driver.SQLStateMapping.newSQLException(SQLStateMapping.java:72)
    at oracle.jdbc.driver.DatabaseError.newSQLException(DatabaseError.java:105)
    at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:168)
    at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:224)
    at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:439)
    at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1302)
    at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3522)
    at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:3574)
    at oracle.jdbc.driver.OraclePreparedStatementWrapper.executeQuery(OraclePreparedStatementWrapper.java:267)
    at oracle_jdbc_driver_OraclePreparedStatementWrapper_Proxy.executeQuery(Unknown Source)
    at oracle.toplink.internal.databaseaccess.DatabaseAccessor.executeSelect(DatabaseAccessor.java:754)
    at oracle.toplink.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:518)
    ... 51 more

    Does this error only occur when the SQL is defined in orm.xml ? Have attempted to run this query in code only?
    --Gordon                                                                                                                                                                                                                                                   

  • Passing SQL string to Stored Procedure

    I have the following package:
    CREATE OR REPLACE PACKAGE PKG_QUERY
    AS
    TYPE CURSOR_TYPE IS REF CURSOR;
    PROCEDURE SP_QUERY(QUERY IN OUT CURSOR_TYPE);
    END;
    CREATE OR REPLACE PACKAGE BODY PKG_QUERY
    AS
    PROCEDURE SP_QUERY(QUERY IN OUT CURSOR_TYPE, IN_SQL IN VARCHAR2)
    AS
    BEGIN
    OPEN QUERY FOR IN_SQL;
    END;
    END;
    Here is what I would like to do. I would like to pass an SQL string that I build in my middle tier and pass it to the SP_QUERY procedure as IN_SQL. I can't seem to get this to compile. If I explicitly type in a select statement (ex. OPEN QUERY FOR SELECT * FROM table), it works fine. Can I pass in an SQL statement as a string and execute the query? Any help that anyone can offer would be GREATLY appreciated!!!!
    Thanks for any help you can offer,
    Michael

    String bigString = getBigString(); // wherever it comes from
    ByteArrayInputStream bais =
             new ByteArrayInputStream(bigString.getBytes());
    PreparedStatement ps = conn.prepareStatement("INSERT INTO SOMETABLE VALUES(?)"); 
    //above is just an example, use your insert statement
    ps.setAsciiStream(1,bais,bigString.length());Of course, that is assuming you have some type of CLOB in your database.

  • For loops and dynamic sql string syntax

    Hi
    is there a why to loop through a dynamic sql string
    normally you would have
    FOR cur IN (select * from emp) LOOP
    but I have a dynamic sql string called l_sql
    I have tried the following
    FOR cur IN l_sql LOOP
    but I get
    PLS-00456: item 'L_SQL' is not a cursorCompilation failed
    Any ideas?

    You will need to use ref cursors and the OPEN v_rc FOR '<your sql string'> and then loop through it as you would with any other OPEN, LOOP, EXIT WHEN, END LOOP syntax

  • Help with Oracle Report Builder and SQL Server2000

    Hey guys,
    I just installed it Oracle Developer Suite10g with Report Builder and I am trying to use Report builder and wants to connect with SQL Server 2000. The problem that I am running in to is SQL Server 2000 i have is Window Authentication so Does not required to enter user name and password. So how can i connect my report builder to SQL server or is it possible to connect Report builder to SQL server?
    Also, I want to create small practice version of database in Oracle how do i do it? what i mean by that is I installed trial version or Oracle developer 10g from www.oracle.com and now trying to get some knowledge with oracle. Could any one can give me some direction in this matter please.
    Thank You
    Key

    Have a look at the reports help for the purpose header and trailer sections. Here is an exert:
    "Report sectioning enables you to define multiple layouts in the same report, each with a different target audience, output format, page layout, page size, or orientation. You can define up to three report sections, each with a body area and a margin area: the names of the sections are Header, Main, and Trailer. By default, a report is defined in the Main section. In the other sections, you can define different layouts, rather than creating multiple separate reports. If you wish, you can use the margin and body of the Header and Trailer sections to create a Header and Trailer page for your reports."

  • To generate sql string of desired row  using function.

    Hi l,
    I return the below query to get sum of vehicles which falls between the specific weight ranges.
    It returns 20 rows( As I selected 4 classification vehicles).I was expect only 4 rows .One row for each classification of vehicles.
    Is there a way if do some loop or decode in my function logic?
    will tht work?
    "(This is only smple. In my real appilication, if I use 15 classification vehicles it returns 320 rows. But i expect only 16 rows - 0 to 15 one row for each classification .Duirng runtime I'm getting an error as buffer string too small)"
    How could I solve this?
    I use this query inside a function and I call that function in a dynamic sql.
    SELECT 'SUM('
        || 'CASE '
        || 'WHEN weight_report_data.weight >=  '|| repo_range_param.min_value ||' 
            AND weight_report_data.weight   <       repo_range_param.max_value
            THEN weight_report_data.weight_count '   
        || 'ELSE 0 '
        || 'END '
        || ') "Class ' || repo_param.r_value || '" '   
          FROM repo_param
          JOIN repo_range_param
            ON repo_param.r_id = repo_range_param.r_id
         WHERE repo_param.r_id    = 1
           AND repo_param.r_group = 'class'
           AND repo_param.r_name  = 'class'
           AND repo_range_param.r_group = 'gvw'
           AND repo_range_param.r_name  = 'gvw'
         ORDER BY CAST(repo_param.r_value AS NUMBER) ASC;
    "sample sql string output when I run the above query "
    SUM(CASE WHEN weight_report_data.weight >=10
             AND weight_report_data.weight  <15
            THEN weight_report_data.weight_count ELSE 0 END ) "Class 0"
    SUM(CASE WHEN weight_report_data.weight >=15
             AND weight_report_data.weight  <20
            THEN weight_report_data.weight_count ELSE 0 END ) "Class 1"
    SUM(CASE WHEN weight_report_data.weight >=5
             AND weight_report_data.weight  <10
            THEN weight_report_data.weight_count ELSE 0 END ) "Class 2"
    SUM(CASE WHEN weight_report_data.weight >=20
             AND weight_report_data.weight  <25
            THEN weight_report_data.weight_count ELSE 0 END ) "Class 3"
    "sample data for the tables involved"
    CREATE  TABLE weight_report_data
    start_date_time       TIMESTAMP      NOT NULL,
    end_date_time         TIMESTAMP      NOT NULL,
    weight                NUMBER(12,0)   NOT NULL,
    weight_count          NUMBER(12,0)   NOT NULL
    INSERT INTO weight_report_data(start_date_time, end_date_time, weight, weight_count)
           VALUES('01-JUL-08 12:00:00','03-JUL-08 12:00:00',4,5);
    INSERT INTO weight_report_data(start_date_time, end_date_time, weight, weight_count)
           VALUES('01-JUL-08 12:00:00','03-JUL-08 12:00:00',3,1);
    INSERT INTO weight_report_data(start_date_time, end_date_time, weight, weight_count)
           VALUES('01-JUL-08 12:00:00','03-JUL-08 12:00:00',8,6);
    INSERT INTO weight_report_data(start_date_time, end_date_time, weight, weight_count)
           VALUES('01-JUL-08 12:00:00','03-JUL-08 12:00:00',25,9);
    CREATE  TABLE repo_param
    R_ID       NUMBER(12,0),
    R_GROUP     VARCHAR2(10),
    R_NAME     VARCHAR2(10),
    R_VALUE     VARCHAR2(10)
    INSERT INTO repo_param(r_id, r_group, r_name, r_value)
           VALUES(1,'class','class',0);
    INSERT INTO repo_param(r_id, r_group, r_name, r_value)
           VALUES(1,'class','class',1);
    INSERT INTO repo_param(r_id, r_group, r_name, r_value)
           VALUES(1,'class','class',2);
    INSERT INTO repo_param(r_id, r_group, r_name, r_value)
           VALUES(1,'class','class',3);
    CREATE  TABLE repo_range_param
    R_ID       NUMBER(12,0),
    R_GROUP     VARCHAR2(10),
    R_NAME     VARCHAR2(10),
    MIN_VALUE NUMBER(3,0),
    MAX_VALUE     NUMBER(3,0)
    INSERT INTO repo_range_param(r_id, r_group, r_name, min_value, max_value)
           VALUES(1,'gvw','gvw',0,5);
    INSERT INTO repo_range_param(r_id, r_group, r_name, min_value, max_value)
           VALUES(1,'gvw','gvw',5,10);
    INSERT INTO repo_range_param(r_id, r_group, r_name, min_value, max_value)
           VALUES(1,'gvw','gvw',10,15);
    INSERT INTO repo_range_param(r_id, r_group, r_name, min_value, max_value)
           VALUES(1,'gvw','gvw',15,20);
           INSERT INTO repo_range_param(r_id, r_group, r_name, min_value, max_value)
           VALUES(1,'gvw','gvw',20,25);
    Thanks in advance
    Edited by: user10641405 on Jun 18, 2009 4:10 PM
    Edited by: user10641405 on Jun 18, 2009 4:15 PM
    Edited by: user10641405 on Jun 18, 2009 4:15 PM
    Edited by: user10641405 on Jun 18, 2009 4:16 PM
    Edited by: user10641405 on Jun 18, 2009 4:17 PM
    Edited by: user10641405 on Jun 18, 2009 7:47 PM
    Edited by: user10641405 on Jun 19, 2009 4:15 PM

    Say you have a 3 tables
    Table name Description rowcount()
    ============================================================================
    weight_report_data report table having weights and counts 4
    repo_param having id column gives different classes 4
    repo_range_param is detail table of repo_param with id 4
              as foreign key and defines weight
              min max ranges.
    Now you need to report
    per class how many weights weights are there ?
    --not understood report id clearly in relation to weight_report_data
    step1:
    need to map each row of weight_report_data againist its class.
    select wrd.weight,wrd.weight_count,(select rp.class||rp.value
    from repo_range_param rrp,
              repo_param rp
    where rrp.id= rp.id
    and rp.id=1 -- add your other join condition
    and wrd.weight between rrp.min and rrp.max ) class_nm
    from weight_report_data wrd ;
    This will give 4 rows , i.e for each row in wrd it tells which class it falls.
    now you want to group by class_nm to get sum or count of weights.
    step2:
    select class_nm,sum(weight), count(weight), sum(weight_count)
    from (
    select wrd.weight,wrd.weight_count,(select rp.class||rp.value
    from repo_range_param rrp,
              repo_param rp
    where rrp.id= rp.id
    and rp.id=1 -- add your other join condition
    and wrd.weight between rrp.min and rrp.max ) class_nm
    from weight_report_data wrd ) wrd_classnm
    group by class_nm;
    I hope this helps .
    suggestion: first analyse and breakdown into stpes how you r going to do if you do by hand and then translate into sql and then optimise

  • SQL Strings in Where Clause - single quotes issue

    All,
    I’m having issues related to SQL String literals when trying to deploy to flash. The complication works fine but I then get a message (see below) stating that a ; is missing. The SQL query and the iview runs fine when we use numeric values or do not apply a where clause on the table.
    I am using Visual Composer that has been packaged with NW2004sSP7_Preview
    VC & Flex Version: 645.7.0.3
    The Error message is get is;
    Error in executing a process for Flex compilation, Error 1033: ';' expected
          (C:usrsapJ2EJC01j2eeclusterserver0GUIMachine_Business_Packagestest_48731FLEX_COMPILATION_FOLEDRAADCN.mxml:269)
    Error 1205: The statement 'Test' is incomplete.
          (C:usrsapJ2EJC01j2eeclusterserver0GUIMachine_Business_Packagestest_48731FLEX_COMPILATION_FOLEDRAADCN.mxml:269)
    Failed to compile AADCN.mxml
    When I goto the deployment file – it has the below line;
    <i>'<Request type="EXECUTE_RELATIONAL" system="BI_JDBC" system_type="SAP_BI_JDBC" maxrows="500" templateid="BIR_SQL"><Objects type="INPUT" shape="OBJ" role="INPUT"><Object type="INPUT_FIELD" id="SQL_STATEMENT" appName="SQL" mapped="0" value=""/></Objects><Objects type="OUTPUT" shape="SET" role="OUTPUT"><Object type="OUTPUT_FIELD" id="name" appName="name"/></Objects><Objects id="1" type="TEMPLATE_PARAMETER"><Object id="2" type="SQL" value="select name from pub.srcompany where name ='Test Company'"/></Objects></Request>';</i>
    It seems that the parser for the flash deployment is prematurely finishing the parse when it hits the single quotation in the SQL string!
    We had a similar error where if we had a carriage return in the SQL (e.g. between the from & the where clause) then the deployment parser was stating that the line finished prematurely. In the deployment file the carriage return forced a new line thus making the message incomplete. Removing the carriage return resolve that issue
    The SQL Preview in the SQL Editor within VC works fine with the string literals in the where clause.
    The functionality compiles & deploys in web dynpro however it does not return the results to the table
    Questions
    1:> Has anyone successfully used flash with string literals in the SQL where clause or had seen this issue in the past?
    2:> Is there a setting to get the SQL working on Web dynpro for the information to be returned that I may have missed?
    Any assistance would be greatly appreciated.
    Best Regards,
    Ian.

    Hey,
    I have worked with SQL Editor a lot. Here's a how to guide I put together on it:
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/6339e7d4-0a01-0010-1c98-db00e52e989a
    Let me know if that helps...
    Prakash

  • Build dynamic SQL query in Database Adapter.

    Hi All,
    I have a requirement to build dynamic sql query at Database Adapter.
    My BPEL process is getting search spec as input from siebel. I need to process this searchspec in BPEL and need to build the SQL query dynamically at Database Adapter to fetch the records from DB.
    it goes like this....
    1. Sieble Search Spec: city1 OR city2 OR city3 OR city4 .....
    I need to build query as
    select * from S_ADDR_PER where city like 'city1' OR city like 'city2' OR city like 'city3' OR city like 'city4' ......
    2. Siebel Search spec: city1 AND country1 AND state1....
    I need to build query as
    Select * from S_ADDR_PER where city like 'city1' AND country like 'country1' AND state like 'state1' ....
    3. Siebel Search spec: state
    I need to build query as
    select * from S_ADDR_PER where state like '%state%';
    Is it feasible in Database Adapter? if its Yes.
    Any guidelines to achieve this?
    Thank you
    Chandra

    Hi All,
    I have a requirement to build dynamic sql query at Database Adapter.
    My BPEL process is getting search spec as input from siebel. I need to process this searchspec in BPEL and need to build the SQL query dynamically at Database Adapter to fetch the records from DB.
    it goes like this....
    1. Sieble Search Spec: city1 OR city2 OR city3 OR city4 .....
    I need to build query as
    select * from S_ADDR_PER where city like 'city1' OR city like 'city2' OR city like 'city3' OR city like 'city4' ......
    2. Siebel Search spec: city1 AND country1 AND state1....
    I need to build query as
    Select * from S_ADDR_PER where city like 'city1' AND country like 'country1' AND state like 'state1' ....
    3. Siebel Search spec: state
    I need to build query as
    select * from S_ADDR_PER where state like '%state%';
    Is it feasible in Database Adapter? if its Yes.
    Any guidelines to achieve this?
    Thank you
    Chandra

  • How to modify the pre generated SQL string in Db adapter

    Hello All,
    I am using a DB adapter to poll a database. So in the configuration of adapter, i have specified the option of logical delete, i want to update to a field PF as 'Y'. In my BPEL process, I want to update those records as 'Y' for their process_Completion field after i am done doing logic on those records.. Actually in the database adapter configuration, we get the SQL string right ?. So inorder to edit that SQL how should we go ahead ?
    I mean i want to poll the database, i want to get like 1000 records for my BPEL Process Instance, and after all those 1000 gets processed and completed. Iwant to get the next 1000. So i want to write a query something like...
    select seqid, id, field1, field2..... from STable a where a.PF = 'N' and exists(select 1 from STable b where b.seqid = a.seqid - 1 and b.PF = 'Y' and b.process_Completion = 'Y')
    So, how to write my custom quesries while polling the database. cant we write custom quesries while we are doing Inbound operation with Dbadapter. Please help me with this thing.
    Thanks,
    N

    Whenever you use a JCA DB Adapter in JDeveloper it creates an OR mapping xml that contains the select/polling query that you might have.
    Below is an example of one such query. You can edit the sql here manually and redeploy your process.
    <querying xsi:type="query-policy">
    <queries>
    <query name="DBConnSelect" xsi:type="read-all-query">
    <call xsi:type="sql-call">
    <sql>SELECT MESSAGE_ID,BU_ID,CREATED_BY FROM MESSAGE_BUFFER where BU_ID IN (3232,4747) and 3 > rownum</sql>
    </call>
    <reference-class>DBConn.MessageBuffer</reference-class>
    <container xsi:type="list-container-policy">
    <collection-type>java.util.Vector</collection-type>
    </container>
    </query>
    </queries>
    In case you need to add parameters to your query you should be able to do that as well while you are creating your DB Adapter.
    Edited by: Arun Pareek on Jun 15, 2011 9:34 AM

  • Converting XML structure to SQL string

    Hi,
    how can I convert an existing XML structure into a SQL string? It's important to do this manually, because there are additional data necessary to complete the recordset.
    The XML structure is:
    <File>
    <Recordset>
    <Column>Data</Column>
    </Recordset>
    </File>
    The additional data are 4 columns for each recordset to implement into the SQL string.
    The SQL string should be something like
    "INSERT INTO table (Add_Column, Column, Column, Column) VALUES (Add_Data, Data, Data, Data)"
    If anyone has source code performing operations like that I'd be grateful 'cause I'm quite new to Java and have not the experience in such transform ops.

    Which package includes xml sax?You can download it from,
    http://java.sun.com/xml/download.html.
    I can send you some sample pgms too, if you want.If you would, I'd be grateful.
    Marko

Maybe you are looking for

  • A required application library failed to load and the product cannot continue

    Seems like I go through this problem time and again with Photoshop + Acrobat CS2 and still have yet to resolve a way of fixing it short of completely wiping my drive and re-installing Windows (XP Pro) The error is "application library failed to load

  • Keytool error: java.lang.Exception: Keystore file does not exist:

    Hi All, While listing the keystore using the command keytool -list, I got the error message that keytool error: java.lang.Exception: Keystore file does not exist: C:\Documents and Settings\subramanian.arivalag\.keystore I noticed there is no file .ke

  • How to split one shared iTunes library associated with two iTunes accounts?

    My boyfriend and I share one computer and have one shared iTunes library on that computer. We both maintain our own separate iTunes accounts. We have very different tastes in music, literature, film, etc. the library has become quite large and my boy

  • Installing OS X Mavericks in virtual box 4.3.6

    Hi I want to install Mavericks on virtual vtual box 4.3.6.. i am using a Macbook Pro (Late 2013).. But when i try to downalod the installtion from Apple Store it would not allow me to download.. how can i get a Mavericks installtion ? Thanks Malinda

  • How to know when a function is running in TRFC mode

    Hi, I have an RFC function and i would like the program to behave differently when called as a TRFC. The question is how to identify when it is being executed asynchronously rather than synchronously. Did I miss something obvious? Any suggestions?