Printing Prepared Statement Query

Hi all,
Is it possible to print Prepared Statement query. When i give System.out.println(query);, i get the query with '?' and not with the actual value sent. How can i print the query with the value passed in place of the '?' ?

Hi all,
Is it possible to print Prepared Statement
tatement query. When i give
System.out.println(query);, i get the query with '?'
and not with the actual value sent. How can i print
the query with the value passed in place of the '?' ?The simple answer is that you can't (AFAIK), but some database drivers are able to log the sql statements.
Kaj

Similar Messages

  • Printing queries in prepared statement

    I have a created a prepared statement. When I execute the query I get an error stating that the SQL isn't correct. I would therefore like to print out the statement so I can see what it looks like. Here is what my code is doing.
    Create a query string with question marks.
    Hand that string off to the preparedStatement constructor.
    Modify that string using setString() One for every question mark.
    Send the query off by calling executeQuery()
    All I want to do is print out what the statement now looks like after the setStrings() are called.
    Thanks,
    -KAP

    That's not a featured guaranteed by the JDBC specification, and because of the way PreparedStatement really works, it can't be.
    You see, PreparedStatement usually does not do string replacement into your SQL; the SQL passed to the database still has the ?s in it and the values are bound later, in the database, to a compiled object that is no longer text.
    A few drivers will give you back the SQL statement if you apply toString() on the PreparedStatement, and maybe even given you the current values of the bind variables, but most won't.
    In fact, normally when you get have invalid SQL with a PreparedStatement, the SQLException is thrown on the prepareStatement method, before the set methods are called; if they're not, then you're probably trying to do an invalid implicit data type conversion. In other words, at least some of the columns in your database are not of character type, and the database is trying to convert your strings to the other type (using its rules, which may be different from Java's rules and may be different from another database's rules), and failing.

  • Show query from prepared statement

    Hi all!
    Does someone knows how to get the whole generated query from a prepared statement?
    I want to know if the parameters are set correctly and therefore want to print it out to screen
    before the query is executed.
    Thanks in advance.

    You can't. At least not using standard JDBC. This is partially because the driver doesn't necessarily generate a query from the prepared statement, it can make a remote procedure call instead, for example.
    Alin.

  • Executiong prepared statement with Like% in SQL Query?

    Hi,
    We are developing GUI project.In which we need to retrieve the contract details based on the Name which we enter in eVision page.Here we will not enter the whole name,we will enter only the part of the name,for example if the actual name is Sun Seebeyond,I will enter only Su.So if there are five records in data base which starts the name with Su.Then it should return the five names..
    For this I am using the prepared statement as
    select name,contractid from table1 where name Like '?%'.
    Here my runtime input value will set to this parameter ?.When I execute this qry in my project I am getting error as "Unable to set parameters on the Object: Invalid parameter index 1".
    If I replace the ? with Su in query itself ,then it works fine..
    Please let me know is there any effective way,using which I can solve..
    Thanks,
    Renga.S.

    Hi,
    This option I already tried and it work fine too.
    I am looking for an option ,where we can handle with in the Query,so we dont need to write any code appending % into the actual valus.
    Thanks,
    Renga.S.

  • Query slow when executing using prepared statement compared to sqlDeveloper

    Oracle version is 10.2.0.1.0.
    I have got a query which when submitted from java code using prepared statement and parameter substitutions, takes more than 20 seconds to give results.
    I can see this SELECT sql sitting there when I run Monitor Sessions through sqlDeveloper, with its wait time increasing and then finally getting through. During that time no other SQLs are waiting.
    DURING THAT TIME then I am able to run the same query (with values included) multiple times using sqlDeveloper, and it gives results in no time.
    Sqldeveloper connects using thin client using lib provided by oracle in windows.
    Java code runs from linux and uses the thin client using lib provided by oracle in linux.
    Both are hitting the same DB running on a separate Linux machine.
    What could be the cause of this problem?
    What db parameters, queries should I run to identify the bottleneck?
    Edited by: user10390517 on Jun 14, 2010 3:06 AM

    Hi Rob,
    at least you should see some differences in the statistics for the different child cursor (the one for the execution in the application should show at least a higher value for ELAPSED_TIME). I would use something like the following query to check the information for the child cursors:
    select sql_id
         , PLAN_HASH_VALUE
         , CHILD_NUMBER
         , EXECUTIONS
         , ELAPSED_TIME
         , USER_IO_WAIT_TIME
         , CONCURRENCY_WAIT_TIME
         , DISK_READS
         , BUFFER_GETS
         , ROWS_PROCESSED
      from v$sql
    where sql_id = your_sql_idRegards
    Martin

  • ? in SQL Queries and not using prepared statements

    Using EclipseLink 1.1.1
    Prepared Statements are disabled
    In our production server something went wrong and one of our Read Queries started erroring. A DatabaseException was thrown and we log the "getQuery.getSQLString()" statement. We found this query in the logs:
    SELECT t1.ID, t1.NAME, t1.DESCRIPTION, t1.EXTREFID, t1.STYLESHEET, t1.DDSVNVERSION, t1.FIRSTNAME, t1.LASTNAME, t1.EMAILADDR, t1.PHONENUMBER, t1.ADDRESS, t1.ADDRESS2, t1.CITY, t1.STATE, t1.POSTALCODE, t1.COUNTRY, t1.ADMINACCTNAME, t1.HASDOCUMENTS, t1.HASTIMEDNOTIFICATIONS, t1.STATUS, t1.ENTRYDATE, t1.EVALEXPDATE, t1.LASTREMINDDATE, t1.FULLUSERS, t1.LIMUSERS, t1.REQUSERS, t1.ISENTERPRISE, t1.EXPDATE, t1.ISDISABLED, t1.DISABLEDDATE, t1.NEEDLICENSEAGREEMENT, t1.ISWARNINGDISABLED, t1.LOCALE, t1.TIMEZONE, t1.CURRENCY, t1.DOMAIN, t1.DOCUMENTSIZE, t1.EXTRADOCUMENTSTORAGE, t1.ONDEMANDOPTIONS, t1.SSOTYPE, t1.RESELLERID, t1.ACCOUNTREPID, t1.LASTUSAGEREPORTDATE, t1.NEXTUSAGEREPORTDATE, t1.USAGEREPORTATTEMPTS FROM T_SSOOPTIONS t0, T_CUSTOMERS t1 WHERE *((((t0.SSOENABLED = ?) AND (t1.SSOTYPE IN (?, ?))) AND (UPPER(t1.DOMAIN) = ?)) AND (t0.CUSTOMERID = t1.ID))*
    Notice the values weren't entered into the where clause. We had to bounce the application to fix the problem. I've never seen this before. I've added more debugging statements to the code - so if this happens again in the future I'll have more information to report on. In the mean time I'm wondering if anyone else has every seen a problem of this nature.

    Database error due to invalid SQL statement.
    I don't have a stack, we were catching the exception and not printing the stack :(
    Like I mentioned in my first post, I added more debugging code (e.printStackTrace()). I understand this is hard to track down without more information. I was just hoping you guys had seen something like this before and had any insight. Like I mentioned before: this is on our production server. I've never seen this type of error before. That particular server (we run in a cluster mode) had been up for several days and then started generating that error. IT bounced the node and everything went back to normal. We have been using toplink for about 5 years now and have never seen this problem, until August 3rd 2009. The only thing that has changed recently is our migration from toplink 10 to EclipseLink. I was wondering if anyone knows if anything had changed in EclipseLink/toplink 11 with the generation of SQL queries.
    I'll keep looking. There is more debugging code in there now. Since the error was "Database error due to invalid SQL statement" this implies the SQL was generated, exited that part of the code and was sent to the db where it failed. I'm afraid the printStackTrace won't help if this error happens again.

  • Prepared statement order by

    I have a problem with order by status in a prepared statement. The list is generated with no order by. However I can not find the error in code.
    Tomcat log print out the query as "com.mysql.jdbc.ServerPreparedStatement[1] - SELECT * FROM tm_game_tables order by 'name';"
    I call the bean from website with:
    <%
    ilia.admin.tm.ListTableBean ltb = new ilia.admin.tm.ListTableBean();
    ltb.setTm_order("name");
    %>
    <table>
    <%=ltb.getList()%>
    </table>Bean code:
    package ilia.admin.tm;
    import ilia.*;
    import java.sql.*;
    import java.io.*;
    import java.util.*;
    public class ListTableBean {
         String tm_order = "";
         public String getTm_order() {
              return tm_order;
         public void setTm_order(String tm_order) {
              this.tm_order = tm_order.trim();
         ConnectionPool pool = new ConnectionPool();
         Connection con = null;
         public String getList() throws ClassNotFoundException{
              String rt = ""; // String to return
              try{
                   con = pool.getConnection();
                   Object[] tm_type_array = {"Real Money", "Play Money"};
                   Object[] tm_status_array = {"Open", "Closed", "Maintance"};
                   PreparedStatement pStmt = con.prepareStatement("SELECT * FROM tm_game_tables order by ?;");
                   pStmt.setString(1, tm_order);
              System.out.println(pStmt);
                   ResultSet rs = pStmt.executeQuery();
                   if(!rs.next()){
                        rt = "";
                   else do {
                        rt = rt + "<tr><td>" + rs.getInt("table_id") + "</td>";
                        rt = rt + "<td>" + rs.getString("name") + "</td>";
                        rt = rt + "<td>" + tm_type_array[rs.getInt("type")] + "</td>";
                        rt = rt + "<td>$" + rs.getDouble("buy_in") + "</td>";
                        rt = rt + "<td>" + rs.getDouble("rake") + "%</td>";
                        rt = rt + "<td>" + tm_status_array[rs.getInt("status")] + "</td>";
                        rt = rt + "<td>" + rs.getString("url_background_image") + "</td>";
                        rt = rt + "<td>" + rs.getString("password") + "</td>";
                        rt = rt + "<td>" + rs.getString("update") + "</td>";
                        rt = rt + "<td>" + rs.getString("user") + "</td></tr>";
                   } while(rs.next());
                   pStmt = null;
                   rs = null;
              catch(Exception exp){
                   System.out.println("Exception: "+ exp);
              finally{
                   pool.putConnection(con);
              return rt;
    }If I test the query as per logs in mysql prompt I get the order by I want,
    Regards
    Andreas

    Still don't order them:
    Print out same query in tomcat log.
    Bean is now:
    package ilia.admin.tm;
    import ilia.*;
    import java.sql.*;
    import java.io.*;
    import java.util.*;
    public class ListTableBean {
         String tm_order = "";
         public String getTm_order() {
              return tm_order;
         public void setTm_order(String tm_order) {
              this.tm_order = tm_order.trim();
         ConnectionPool pool = new ConnectionPool();
         Connection con = null;
         public String getList() throws ClassNotFoundException{
              String rt = ""; // String to return
              try{
                   con = pool.getConnection();
                   Object[] tm_type_array = {"Real Money", "Play Money"};
                   Object[] tm_status_array = {"Open", "Closed", "Maintance"};
                   PreparedStatement pStmt = con.prepareStatement("SELECT * FROM tm_game_tables order by ?;");
                   pStmt.setString(1, tm_order);
                   ResultSet rs = pStmt.executeQuery();
              System.out.println(pStmt);
                   if(!rs.next()){
                        rt = "";
                   else do {
                        rt = rt + "<tr><td>" + rs.getInt("table_id") + "</td>";
                        rt = rt + "<td>" + rs.getString("name") + "</td>";
                        rt = rt + "<td>" + tm_type_array[rs.getInt("type")] + "</td>";
                        rt = rt + "<td>$" + rs.getDouble("buy_in") + "</td>";
                        rt = rt + "<td>" + rs.getDouble("rake") + "%</td>";
                        rt = rt + "<td>" + tm_status_array[rs.getInt("status")] + "</td>";
                        rt = rt + "<td>" + rs.getString("url_background_image") + "</td>";
                        rt = rt + "<td>" + rs.getString("password") + "</td>";
                        rt = rt + "<td>" + rs.getString("update") + "</td>";
                        rt = rt + "<td>" + rs.getString("user") + "</td></tr>";
                   } while(rs.next());
                   pStmt = null;
                   rs = null;
              catch(Exception exp){
                   System.out.println("Exception: "+ exp);
              finally{
                   pool.putConnection(con);
              return rt;
    }However if I change ststement to "PreparedStatement pStmt = con.prepareStatement("SELECT * FROM tm_game_tables order by " + tm_order + ";");" as earlier posted wrote I get the order by. However I think that is incorrect prepared statement standard, isn't it?
    Regards
    Andreas

  • Proving prepared statements are being reused

    How can I prove that a prepared statement from a JDBC driver is being reused / pooled ?
    What essentially I want to do is to have prepared statements reused to reduce hard parsing ... but I also need to prove that the statements are being reused. If I query the statement in V$SQLAREA, the column PARSE_CALLS does not seem to be distinguish between hard parse and soft parse:
    http://download-west.oracle.com/docs/cd/B10501_01/server.920/a96536/ch3204.htm#1126299
    I am only interested for now in proving the just ONE statement is being reused ... which mean that the number of hard parses is very low compared to the number of soft parses for that ONE statement.
    Regards,
    jms
    Message was edited by:
    jms

    Hi,
    No, parse calls is all soft and hard parse together. What you would see, if used absolutely correctly, would be 1 hard parse per session and many executions.
    But since v$sql is obviously not linked to v$session other than at the time of exection, you see the aggregated parse calls and executions for each cursor. So what you should see is parse calls go up relatively slowly to the number of exections.
    However, you can see soft and hard parses using the v$sesstat and v$statname views so you can see soft and hard parses on a session by session basis, be these are again aggregated, so you can't see soft / hard counts per cursor, only the total for a session.
    What I see a lot of the time is they don't get it quite right, so hard parses is low but soft parses are high, so they are still parsing when they don't need to, but at least they are binding and using shareable SQL, which is a step in the right direction.
    When I say 'they', it is a generic reference to all Java/.Nyet programmers writing front end code where they just don't 'get' parsing and binding because it's just too complicated and hey, SQL Server isn't like this...!
    HTH
    Chris

  • When to use prepared statement in java?

    Hi all,
    If we have query like select * from {tablename} (Here tablename is the variable) then will the use of prepared staement improve the performance? My guess is use of statement in this case is a better option rather than prepared statement as the tablename may change for every other query.I think are not useful if tablename changes.They are useful only when the where clause has dynamic values.

    cantor wrote:
    Are you sure that your approach is possible? The next example causes exception for me.
    PreparedStatement ps = conn.prepareStatement("select * from ?");
    ps.setString(1, "TABLE_NAME");
    ps.executeQuery();
    I didn't say that he should solve it in that way. He should create one prepared statement like this "select a, b, c from tablename1" and another prepared statement when he wants to execute "select d, e, f from tablename2"
    >
    And as I understand, this code will not improve perfomance (and even will not work). As I said it can.
    Prepared statements make possible usage compiled queries inside DB. When DB gets prepared statement call, it need to parse it only once. And it can collect some statistic to improve execution plan. But when table name is not specified, this approach will not work.Yes it might. There are database drivers that can cache prepared statements and it's isn't likely that he executes that query on more than e.g. 20 tables?
    The database can also cache compiled statements in a cache.
    Kaj

  • How do I handle NULL returns from prepared statement?

    Thanks in advance to all those who respond. As a beginner with Java/JSP/JDBC, I need all the help I can get!
    Here's the problem...
    I'm using a prepared statement in JSP to query a MySQL database.
    If there is a value to return, everything works properly.
    If the query returns a NULL (empty set) value, I get the following error:
    javax.servlet.ServletException: Before start of result set
    Here's the code (no negative comments please...I know I'm violating some conventions! I'll restructure it later. Right now I just need help with handling the NULL case):
    <%
    Driver DriverAppt = (Driver)Class.forName(MM_test_DRIVER).newInstance();
    Connection ConnAppt = DriverManager.getConnection(MM_test_STRING,MM_test_USERNAME,MM_test_PASSWORD);PreparedStatement StatementAppt = ConnAppt.prepareStatement("SELECT lastname FROM appts_pid1 WHERE user_id = " + Recordset1__MMColParam + " AND year = " + yy + " AND month = '" + months[mm] + "' AND date = " + dates[dd] + " AND appttime = '16:15:00'");
    ResultSet Appt = StatementAppt.executeQuery();
    boolean Appt_isEmpty = !Appt.first();
    boolean Appt_hasData = !Appt_isEmpty;
    Object Appt_data;
    int Appt_numRows = 0;
    %>
    Thanks for the help!!!

    I think I have a better handle on what's occurring here. To cut to the heart of the problem, I'm going to give a very simple example that illustrates what type of error handling I need.
    HERE'S THE EXAMPLE:
    Let's say that I have a database of users. There are only two columns in the database: user_id and lastname. There are only 2 users, user_id "1" has lastname "Jones" and user_id "2" has lastname "Smith".
    I built a very simple web interface that let's a user enter a number to see if there's a lastname associated with that record. The user has no way of knowing if the user_id exists or not, so they may or may not enter a valid number.
    If the user enters a valid user_id (in this case "1" or "2"), then the correct lastname is displayed. If the user enters an invalid user_id (in this case, anything other than "1" or "2") then I get the same "Before start of result set" error that I'm getting in my real application.
    So, the question is: WHERE IN THIS CODE WOULD I HANDLE THE RETURN OF AN EMPTY SET?
    The goal here is to have the sentence say "The user's lastname is .", basically returning null. If there has to be a value, then have the last sentence say "The user's lastname is unknown."
    If you can solve this simple example, you'll have also solved the problem with my main application!!!! :-)
    Here's the example code:
    <%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %>
    <%@ include file="Connections/example.jsp" %>
    <%
    String Recordset1__MMColParam = "1";
    if (request.getParameter("user_id") !=null) {Recordset1__MMColParam = (String)request.getParameter("user_id");}
    %>
    <%
    Driver DriverRecordset1 = (Driver)Class.forName(MM_example_DRIVER).newInstance();
    Connection ConnRecordset1 = DriverManager.getConnection(MM_example_STRING,MM_example_USERNAME,MM_example_PASSWORD);
    PreparedStatement StatementRecordset1 = ConnRecordset1.prepareStatement("SELECT * FROM test_table WHERE user_id = " + Recordset1__MMColParam + "");
    ResultSet Recordset1 = StatementRecordset1.executeQuery();
    boolean Recordset1_isEmpty = !Recordset1.next();
    boolean Recordset1_hasData = !Recordset1_isEmpty;
    Object Recordset1_data;
    int Recordset1_numRows = 0;
    %>
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    <body>
    <form action="test.jsp" method="get" enctype="application/x-www-form-urlencoded" name="form1" target="_self">
    <p> Submit a user id and a lastname will be displayed.</p>
    <p>
    <input type="text" name="user_id">
    <input type="submit" name="" value="Submit">
    </p>
    </form>
    <p>The User's lastname is <%=(((Recordset1_data = Recordset1.getObject("lastname"))==null || Recordset1.wasNull())?"":Recordset1_data)%>.</p>
    </body>
    </html>
    <%
    Recordset1.close();
    StatementRecordset1.close();
    ConnRecordset1.close();
    %>
    A huge "THANK YOU!!!!" to all those who've helped me here!!!

  • Pass table name as parameter in prepared Statement

    Can I pass table name as parameter in prepared Statement
    for example
    select * from ? where name =?
    when i use setString method for passing parameters this method append single colon before and after of this parameter but table name should be send with out colon as SQL Spec.
    I have another way to make sql query in programing but i have a case where i have limitation of that thing so please tell me is it possible with prepared Statment SetXXx methods or not ?
    Thanks
    Haroon Idrees.

    haroonob wrote:
    I know ? is use for data only my question is this way to pass table name as parameterI assume you mean "how can I do it?" As I have already answered "is this the way?" with no.
    Well, I would say (ugly as it is) String concatenation, or stored procedures.

  • Prepared statements related problem

    Hi,
    i have this strange problem with prepared statements i think.
    When i execute an insert query without prepared statements i works fine (always), when i use prepared statements it sometimes gives a db error saying i'm trying to insert a null value.
    The problem is that I'm not!!!
    If i were why does it work sometimes?
    It may be a bug but i don't know where to look for it... is it a prepared statements, application server or db2 problem?

    This is the code...
         public void insertArticolo(Articolo item) throws Exception {
              PreparedStatement ps = null;
                   try {          
                        StringBuffer sql = new StringBuffer("insert into RUW.RUWT1_ARTICOLO (");
                        sql.append("C_ENTE, C_CONCESSIONE,N_ANNO_RUOLO,N_PROGR_RUOLO,N_PARTITA,N_PROGR_PARTITA,N_PROGR_TRIBUTO, ");
                        sql.append("C_TRIBUTO, C_TIPO_UFF,C_UFFICIO,");
                        sql.append("C_TIPO_IMP, N_ANNO_IMP, L_CARICO, S_ARTICOLO");
                        sql.append(") values (");
                        sql.append("?" + ", ");
                        sql.append("?" + ", ");
                        sql.append("?" + ", ");
                        sql.append("?" + ", ");
                        sql.append("?" + ", ");
                        sql.append("?" + ", ");
                        sql.append("?" + ", ");
                        sql.append("?" + ", ");
                        sql.append("?" + ", ");
                        sql.append("?" + ", ");
                        sql.append("?" + ", ");
                        sql.append("?" + ", ");
                        sql.append("?" + ", ");
                        sql.append("?");
                        sql.append(")");
                        ps = connectionCreatePreparedStatement(sql.toString());
                        System.out.println(sql.toString());
                        KeyArticolo keyArticolo = item.getKeyArticolo();
                        KeyPartita keyPartita = keyArticolo.getKeyPartita();
                        Ente ente = keyPartita.getKeyRuolo().getEnte();
                        System.out.println("/"+ ente.getCodEnte()+ "/");
                        System.out.println("/"+ keyPartita.getKeyRuolo().getConcessione().getCodConc()+ "/");
                        System.out.println("/"+ keyPartita.getKeyRuolo().getAnnoRuolo()+ "/");
                        System.out.println("/"+ keyPartita.getKeyRuolo().getProgRuolo()+ "/");
                        System.out.println("/"+ keyPartita.getNumPartita()+ "/");
                        System.out.println("/"+ keyPartita.getProgPartita()+ "/");
                        System.out.println("/"+ item.getKeyArticolo().getProgArticolo()+ "/");
                        System.out.println("/"+ item.getCodEntrata()+ "/");
                        System.out.println("/"+ ente.getTipoUfficio()+ "/");
                        System.out.println("/"+ ente.getCodUfficio()+ "/");
                        System.out.println("/"+ item.getTipoImposta()+ "/");
                        System.out.println("/"+ item.getAnnoImposta()+ "/");
                        System.out.println("/"+ item.getCaricoOrigine()+ "/");
                        if (item.getDescArticolo().equals("")) {
                             item.setDescArticolo(" ");
                        System.out.println("/"+ item.getDescArticolo()+ "/");
                        ps.setLong(1,ente.getCodEnte());
                        ps.setLong(2,keyPartita.getKeyRuolo().getConcessione().getCodConc());
                        ps.setLong(3,keyPartita.getKeyRuolo().getAnnoRuolo());
                        ps.setLong(4,keyPartita.getKeyRuolo().getProgRuolo());
                        ps.setLong(5,keyPartita.getNumPartita());
                        ps.setLong(6,keyPartita.getProgPartita());
                        ps.setLong(7,item.getKeyArticolo().getProgArticolo());
                        ps.setString(8,item.getCodEntrata());
                        ps.setString(9,ente.getTipoUfficio());
                        ps.setString(10,ente.getCodUfficio());
                        ps.setString(11,item.getTipoImposta());
                        ps.setLong(12,item.getAnnoImposta());
                        ps.setLong(13,item.getCaricoOrigine());
                        ps.setString(14,item.getDescArticolo());
                        ps.executeUpdate();
                   catch (Exception e) {
                        e.printStackTrace();
                        connectionCloseStatement(ps);
                        throw e;
              }and this is the result of the systemout
    [10/03/06 14.07.07:051 CET] 76357635 SystemOut O insert into RUW.RUWT1_ARTICOLO (C_ENTE, C_CONCESSIONE,N_ANNO_RUOLO,N_PROGR_RUOLO,N_PARTITA,N_PROGR_PARTITA,N_PROGR_TRIBUTO, C_TRIBUTO, C_TIPO_UFF,C_UFFICIO,C_TIPO_IMP, N_ANNO_IMP, L_CARICO, S_ARTICOLO) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
    /13199/
    /66/
    /2002/
    /1564/
    /28330/
    /1/
    /2/
    /0997/
    /120/
    /2002/
    /11900/
    / /

  • Using partition in prepared statement

    Hello,
    I am connecting to an oracle 9i database and write a prepared statement like
    String query = "SELECT * FROM ADM.TABLE1 PARTITION (TABLE1_?)";
    PreparedStatement pstmt = dbConnection.prepareStatement(query);
    pstmt.setString(1, "20" + callDate); // Partitions are like TABLE1_20030605
    ResultSet rs = pstmt.executeQuery();
    I get this error ORA-00933: SQL command not properly ended
    Any ideas if i am substituting the value correctly or if this is the right way to use prepared statement ?

    It is the wrong way to use a prepared statement.
    You will need to create the string dynamically.

  • Oracle Prepared Statement and spaces in field

    I have a field that is defined as char(10). It has characters like '39' in it. When I select against it using standard SQL (where clause) I get results. When I use it in the where clause of a prepared statement it does not return any rows.
    If I have the field defined as char(2) the prepared statement works.
    If I have the field defined as varchar2(10) and loaded with '39' the prepared statement works.
    If I have the field defined as varchar2(10) and loaded with '39 ' the prepared statement returns no results.
    I really do not think this is a JDBC problem. However, since Oracle's site basically <expletive deleted>, I am hoping someone here has a solution.
    Thanks in advance if you can help.

    Let me clarify.
    I cannot remove the whitespace from the data in the database. I do not need the whitespace to do the query if I am not using a Prepared Statement. This seems to be a problem with the way Oracle is handling the prepared statement. (hence.. my thinking that this is really not a JDBC problem at all.. but I could be wrong.)

  • Problem with Prepared Statement & MS Access

    Hi
    I have tried to find some info about this but can't see anything specific to what I think the problem may be. Hopefully someone can point me in the right direction.I am trying to get information out of an MS Access database using a Prepared Statement but I am getting strange results.
    When I run the query in the database it gives me the correct totals (�51) for 4 records. When I run the Prepared Statement ,I get 81. Has it got anything to do with the data type I am using( sorry if this is a really basic question). here is my code- the connection etc is elsewhere.
    private void getReportMoneyTotal() throws SQLException
              Calendar todayTotal =Calendar.getInstance() ;
               SimpleDateFormat reportDateFormat = new SimpleDateFormat("dd MM yyyy");
              PreparedStatement preparedT =context.getConnection().prepareStatement(
                   "SELECT Sum(tblSession.Fee) AS Total, Count(tblBooking.BookingID) AS CountOfBookingID FROM tblSession INNER JOIN "+
                   "(tblBooking INNER JOIN tblCustomer_Booking ON tblBooking.BookingID = tblCustomer_Booking.BookingID) ON tblSession.SessionID = tblBooking.SessionID "+
                   "WHERE (((tblBooking.EventDate)>DateAdd('m',-1,#"+reportDateFormat.format(todayTotal.getTime())+"#)) AND ((tblSession.Session)='Morning' Or (tblSession.Session)='Evening')) OR (((tblSession.Session)='Afternoon') AND ((tblBooking.Extension)=Yes))"
              ResultSet resultTotal =preparedT.executeQuery();
              resultTotal.next();
              Double total =resultTotal.getDouble("Total");
              Locale locale = new Locale("GBP");
            NumberFormat gbpFormat = NumberFormat.getCurrencyInstance(locale);
              System.out.println(gbpFormat.format(total));
              preparedT.close();
         }I do realise that my code probably isn't very elegant but I'm only learning!

    Hi Matt--
    I am not clear if you are saving the url with the # # around
    the text or if
    the
    data already contains the # marks.
    When you insert a link, you want to make sure you insert is
    insert into table ( link1) values ( <cfqueryparam
    cfsqltype="cf_sql_varchar"
    value='#linkvaluehere#'> )
    remember to
    1) enclose your data's value inside quotes (some databases
    are picky about
    single v. double quotes).
    2) if it IS in quotes, swap doubles for singles and see if
    that helps.
    3) make sure your data being saved is NOT double hashed like
    '##linkvalueher##'. Double ##'s tell
    Coldfusion not to treat it as a variable.
    hope his helps,
    tami
    "Mattastic" <[email protected]> wrote in
    message
    news:f9c7h0$8ub$[email protected]..
    | Hi Folks,
    |
    | I'm storing a link in a nvarchar field in SQL server,
    www.foo.co.uk, it
    looks
    | and works fine in SQL server. Problem occurs when I setup
    an ADP in Access
    and
    | insert links. Certain links have a hash symbol around them.
    so
    |
    http://www.foo.co.uk, would be #
    http://www.foo.co.uk# which is
    causing
    problems.
    |
    | Can anyone tell me why this is happening? and how to stop
    it?
    |
    | Thankyou
    |

Maybe you are looking for

  • How to Create a BC4J messageChoice using an View?

    I just started using UIX (today in fact) and would like to know how to use a View Object to populate a BC4J messageChoice. I've created an form to update a table. One of the fields is cost center. I store the different cost centers in a seperate tabl

  • How to test php when creating in DW CS4

    I am a bit confused. Here is my set up: I have DW CS4 on my laptop and I am developing a site for a client. I have a local copy and I have set up a remote folder using FTP and utilize this mainly to put my pages on the server. I do have dynamic conte

  • HT4796 Mac can't find Window XP computer

    The Migration Assistant is open on a Windows XP computer and "waiting for your Mac to connect", and the Mac is searching but they can't find each other.  What should I do to help them?  Both are on the same ethernet.

  • Swf file inclusion

    Hi, How can i embedd a  swf(flash file) in the login of the enterprise portal .i changed the images and text using the logon par file downloaded to nwds . i want to embed a swf file in place of the images in portal login Thanks&Regards Prasad

  • Chapters out of order

    When I put an audiobook from CDs onto the iPod, I put every one of the 39 chapters in order on the playlist. After syncing, the iPod no longer has the chapters in order. How should I correct this? AMD   Windows XP Pro