Sql syntax in jsp

Hey All!
Im trying ot use a a bean to select data from a table where email != ''
The funny thing is my code works in one couple of jsp/bean but not in another, even though it's the exact same code.
This works
The Bean:
String sql = "SELECT applicantid, firstname, lastname, dob, " +
"homestreet, homestate, homecity, homezip, " +
"email, college, major, standing, " +
"graddate, schstreet, schcity, schstate, " +
"schzip, schphone, resOne, resTwo, " +
"resThree, waiver, bioletter, password, " +
"homephone " +
"FROM apptest " +
"WHERE " + filter + " " +
"ORDER BY " + orderBy;
The filter is the String "email != ''" and orderBy ="lastname"
Works perfectly!
But when I use similar code for another table
Code:
String sql = "SELECT providerid, applicantid, pin, title, " +
"company, firstname, lastname, phone, " +
"email, recletter " +
"FROM provtest " +
"WHERE " + filter + " " +
"ORDER BY " + orderBy;
with filter as "email != '' " and orderBy = "lastname"
I get the following error:
Error in findRecords ProviderUtility(Syntax error or access violation, message from server: "You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1")
Keep in mind that email != '' (these are single quotes)
I am really baffled.
Ike

"The funny thing is my code works in one couple of jsp/bean but not in another, even though it's the exact same code."
If it's EXACTLY the same code, what did you need another bean for?
If you needed a new bean, then it's not exactly the same.
Why aren't you using PreparedStatement to escape strings and dates for you?
Believe the engine when it tells you there's a mistake.
%

Similar Messages

  • The syntax for accessing MS SQL db from JSP

    Can anybody help me with the syntax for accessing MS SQL db from JSP???
    This is what I do when I use MySQL:
    Class.forName( "org.gjt.mm.mysql.Driver" );
    Connection conn = DriverManager.getConnection(
         "jdbc:mysql:://um" ,
    What do I write when it is MS SQL and where do I install the driver
    BR Soren

    Can anybody help me with the syntax for accessing MS
    SQL db from JSP???
    This is what I do when I use MySQL:
    Class.forName( "org.gjt.mm.mysql.Driver" );
    Connection conn = DriverManager.getConnection(
    "jdbc:mysql:://um" ,
    What do I write when it is MS SQL and where do I
    install the driver
    BR Soren
    One way of doing this is to use ODBC. Here's an example:
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection conn = DriverManager.getConnection("jdbc:odbc:<odbc name>", "<login>", "<password>");

  • SQL query with JSP and WML-parameters

    Hey,
    Could you help me?
    I'm trying to do the following. WML deck card 1 send parameter to same WML deck's card help. I try to read the parameter with JSP in card help by putting the parameter to SQL query, but it doesn't work. I can read the parameter with WML in card help. I can also print the value of the parameter with JSP if I generate WML with JSP.
    /*parameter sending from card 1 to card help*/
    out.println("<go href='#helpcard'>");
    out.println("<setvar name='valittukurssi' value='$(valittukurssi)'/>");
    /*parameter read with WML in card help */
    <p>Valitse kurssi.
    $valittukurssi</p>
    /'parameter read with JSP by generating WML with JSP*/
    out.println("<p>$valittukurssi</p>");
    /* SQL query with JSP */
    ResultSet uudettulokset = uusilause.executeQuery("select * from kurssi where lyhenne='$valittukurssi'");
    Thanks,
    Rampe

    You're problem is easy to fix. You're confusing WML variables with JSP variables. See below:
    >
    /*parameter sending from card 1 to card help*/
    out.println("<go href='#helpcard'>");
    out.println("<setvar name='valittukurssi'
    value='$(valittukurssi)'/>");
    Above you set a var that will work on the phone, not in JSP.
    /*parameter read with WML in card help */
    <p>Valitse kurssi.
    $valittukurssi</p>
    Yes the above does display the parameter, because it is a client side WML var, but you cannot use this variable in the JSP code (that's why your SWL fails).
    /'parameter read with JSP by generating WML with
    JSP*/
    out.println("<p>$valittukurssi</p>");Here's you're problem, the above line is EXACTLY the same as the one before it. When the container parses through this JSP code it translates the above line to:
    <p>$valittukurssi</p> on the WML page and the CLIENT uses it's local variable to display it.
    What you need and want is to have a variable that can be used in JSP code and output to your WML page. Here's how it's done:
    out.println("<go href='#helpcard'>");
    String some_name = "valittukurssi";
    out.println("<setvar name='"+some_name+"'
    value='$("+some_name+")'/>");
    //note that you may have to escape the ( and ) with a \
    //so we displayed the variable above into the WML page, now we can use it in the SQL query:
    /* SQL query with JSP */
    ResultSet uudettulokset =
    uusilause.executeQuery("select * from kurssi where
    lyhenne='"+some_name+"'");//the end of the command is: " ' " ) ;
    Frank Krul
    Got Node?

  • PL/SQL error in JSP Reports

    Hi,
    I am trying to create a simple PL/SQL in a JSP report thar returns a column's value as below:
    Return :RES_COM_CODE ;
    I am getting an error as below:
    javax.servlet.jsp.JspException: REP-0724: Cannot get the value of Column 'RES_COM_CODE' here. REP-1401: 'cf_1formula': Fatal PL/SQL error occurred.
    Can someone please tell me how to solve the error above? The CF_1 is in the same group as 'RES_COM_CODE' .
    Thank you in advance.
    Cheers,
    Tan

    it seems to be a bug in oracle.
    you need to apply the patchset 9.0.4.1 to get this issue resolved.
    .0.4.1 3240140 This fix will solve the REP-0724 error (and engine crash/hang) which you web only report and formula column accessing database columns in the group

  • SQL Developer 1.1.0.21: Issues with Data Grid and SQL syntax checking

    In this new release of SQL Dev, when I execute a SQL in the SQL Worksheet and click in the Data Grid in the Results tab and try to navigate within a record using arrow keys, the grid cell enters into edit mode by default and so I cannot use the Left or Right arrow keys to navigate the grid. I am forced to use tab key to navigate. This is counter intuitive in my opinion.
    Is there any option to change this behavior?
    Another issue that I have come across is with SQL syntax checking. In some cases, when I press F9 to execute a SQL, it shows the SQL as executed i.e. shows something like 0.0134 seconds in the toolbar and no results displayed. In reality, the SQL had some syntax error which were NOT reported. This can be frustrating since now I have to fall back to SQL*Plus or TOAD just for syntax check.
    I like the fact that SQLDev highlights the current SQL but it would be more useful if it just indicated the first line of the current sql instead of highlighting the whole sql.
    Manish

    "In this new release of SQL Dev, when I execute a SQL in the SQL Worksheet and click in the Data Grid in the Results tab and try to navigate within a record using arrow keys, the grid cell enters into edit mode by default and so I cannot use the Left or Right arrow keys to navigate the grid. I am forced to use tab key to navigate. This is counter intuitive in my opinion."
    In the "Results" tab, Click Ctrl & Tab keys (at the same time) or with mouse click on any cell other than the first column (a sequence or rownum), you will be able to navigate using the arrow keys.
    "Another issue that I have come across is with SQL syntax checking. In some cases, when I press F9 to execute a SQL, it shows the SQL as executed i.e. shows something like 0.0134 seconds in the toolbar and no results displayed. In reality, the SQL had some syntax error which were NOT reported. This can be frustrating since now I have to fall back to SQL*Plus or TOAD just for syntax check."
    The 0.0134 seconds could be the result of the most recently executed successful statement. Check the Script Output tab for errors. Use F5 (Run Script option) instead of F9.
    "I like the fact that SQLDev highlights the current SQL but it would be more useful if it just indicated the first line of the current sql instead of highlighting the whole sql."
    On the SQL statement (or code), Right Click -> Format SQL (or press Ctrl & B), proper formatting would help.
    I use version 1.0.0.15.57 and seems to be working allright.
    - Babu Rangasamy

  • Call PL/SQL packages in JSP

    I would like to call PL/SQL packages in JSP. I am new in Java world. So, kindly tell code about to call packages from oracle. I will be thankful to all those experts who will help a student such as me.
    I will be anxious to your response.
    plz
    plz

    Dear sir,
    I am really thankful to you. I have to verify password in oracle.
    Id and password verification is writting in package's function. Id and password are oracle users. Like scott in Oracle. I think it is possible.
    Kindly assist me.
    If u feel easy then kindly contact me at [email protected] or tell me your email address. Plz

  • SQL Error in JSP

    Could anyone tell me why I get a SQL Syntax error for this query?
    "SELECT tblrapporti.id_rapporto, tblrapporti.desc_breve, tblrapporti.desc_lunga, tblrapporti.cod_contab, tblrapporti.cod_banca, tblagenzie.desc_breve, tblbanche.desc_breve
    FROM tblbanche INNER JOIN (tblrapporti INNER JOIN tblagenzie ON tblrapporti.id_agenzia = tblagenzie.id_agenzia) ON tblbanche.id_banca = tblagenzie.id_banca"
    I'm using MySQL 2.3
    Executing query into MySQL DBMS, I get the same error too.
    Any suggestions?
    Thanks in advance.
    Fil

    Try something more like;
    SELECT
    tblrapporti.id_rapporto,
    tblrapporti.desc_breve,
    tblrapporti.desc_lunga,
    tblrapporti.cod_contab,
    tblrapporti.cod_banca,
    tblagenzie.desc_breve,
    tblbanche.desc_breve
    FROM tblrapporti, tblagenzie, tblbanche
    WHERE
    tblrapporti.id_agenzia = tblagenzie.id_agenzia AND
    tblbanche.id_banca = tblagenzie.id_banca AND...

  • SQL*Loader in JSP

    SQL LOADER in JSP i know Oracle 10g have a utility sqlldr
    Can i submit file(CSV) from a remote client to server which can be than upload into Oracle DB.
    i know how to upload file into root directory
    How can i use JSP to run sqlldr on server so that the process become automatic.
    I know how to give command sqlldr in Command prompt but what is the scripting on JSP so that sqlldr can run and csv file get uploaded.
    where from i can info about it please let me know if you have any idea
    thanks
    Message was edited by:
    UDAY

    Hi
    Can you please check that is it possible to execute OS commands in JSP ??
    If possible then you can very well execute SQLLDR in JSP .
    thanks
    Note : This is Oracle database general forum.

  • SQL Syntax Issue

    This is a weird one!!!
    I am using Dreamweaver/php/mysql and I am in the process of
    developing the forms that edit articles that have been added to the
    CMS. I have a page called edit.php which has the current list of
    articles. Each article has a radio button next to it and have given
    it an id of "id" (which is what I called it in the DB). On
    selecting this article, and hitting submit, this should load up a
    editnews2.php. On editnews2.php I have a filtered recordset that
    filters on "id " so that it loads the article selected into the
    editnews2 form. I have bound the fields in the form to the related
    fields in the recordset.
    When I test this out using the TEST button, in the recordset
    pop-up window and enter an id, it retrieves the correct article
    from the database. However, when I do it using the forms, I get an
    error:
    "You have an error in your SQL syntax; check the manual that
    corresponds to your Mysql server version for the right syntax to
    use near " at line 1"
    This is really weird because the recordset works and
    retreives the data no problems, which mean the connection file path
    is correct and other parameters are correct. I have tried lots of
    times to try and figure this out but I am now really stuck.
    Could anyone shed some light on this one?
    regards
    orange22

    orange22 wrote:
    > When I test this out using the TEST button, in the
    recordset pop-up window and
    > enter an id, it retrieves the correct article from the
    database. However, when
    > I do it using the forms, I get an error:
    >
    > "You have an error in your SQL syntax; check the manual
    that corresponds to
    > your Mysql server version for the right syntax to use
    near " at line 1"
    What that means is that the way Dreamweaver is building your
    query
    contains a mistake - probably an extra quotation mark or
    something like
    that.
    Go into Code view and use echo to display the actual SQL
    query being
    sent to the database. That will give you a clue as to where
    to start
    troubleshooting the rest of the code.
    David Powers, Adobe Community Expert
    Author, "The Essential Guide to Dreamweaver CS3" (friends of
    ED)
    Author, "PHP Solutions" (friends of ED)
    http://foundationphp.com/

  • SQL problem with JSP

    In sql statements with JSP. Heres the deal:
    Access database:
    Tablename: EVENT
    FieldName: event_id
    DataType: Number
    I want to compare the event_id to an integer variable called "var" in a WHERE clause in an SQL statement through a JSP.
    String query = "SELECT * FROM EVENT WHERE EVENT.event_id = 'var' ";
    It says "Data type mismatch in criteria expression."
    Any Suggestions? I thought this should be straight forward! am i missing something?

    if i am reading correctly "var" is an int variable correct? If this is the case then the following will work;
    String query = "SELECT * FROM EVENT WHERE EVENT.event_id = " + Interger.toString(var) ;
    Hope that helps ( and i hope i read your problem correctly)

  • Error in SQL syntax

    Hi all,
    I have an SQL database which up untli about 20 minutes ago was fine.  I have a complex contact form whic is (was) all finished.  I have added a couple more tables to the database (now totalling 4), in order to create a registration / login page.
    (Is it okay to have 4 tables in 1 database?)
    Anyway.  I have just finished with the login stuff and all works fine.  I decided to have a quick look around the site and make sure everything is okay - but for some reason when I navigate to the "complex contact form" - I get this message:
    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ASCE LIMIT 0, 150' at line 1
    The registration wizard and login pages still work, and in general the site is browseable.  But this page will not work and I have no idea why?
    Does anyone have any suggestion?  All I have done since it worked is add 2 other tables as I said....
    Thank you / please help!
    NJ

    There was a typo in my previous post. There should be only one $ in $query_recordsetName. I should also have added that "recordsetName" is the name of your recordset. I would have thought it was obvious, but I see you're limiting the number of results, so the name is slightly different.
    The other thing is that you have not put it where I told you. Apart from that...
    $query_rscontacts1 = "SELECT contacts.Logo, contacts.Industries,
    contacts.coverage, contacts.misc, contacts.id, contacts.email,
    contacts.website FROM contacts WHERE {$NXTFilter_rscontacts1} ORDER BY
    {$NXTSort_rscontacts1}";
    $query_limit_rscontacts1 = sprintf("%s LIMIT %d, %d", $query_rscontacts1, $startRow_rscontacts1, $maxRows_rscontacts1);
    echo $query_limit_rscontacts1 . '<br />';
    $rscontacts1 = mysql_query($query_limit_rscontacts1, $Contacts) or die(mysql_error());

  • Error with SQL syntax

    I'm trying to get onto a website i could normally get into but all it says is this
    you have an error in your SQL syntax;check the manual that corresponds to your MySQL server version for the right syntax to use near') and adlx.'action' !=  2' at line 1
    I'm not good with computers and I've never heard of this i need some help, I may just be stupid but i seriously need some help here
    preferably instructions for a hp computer

    This looks to be an error with the web site you are visiting, not a problem with your PC.  I suggest you contact the web site owner.  The error suggests a problem with programming against a MySQL database, which is not a Microsoft technology.
    Dan Guzman, SQL Server MVP, http://www.dbdelta.com

  • ANSI SQL Syntax - What belongs to join-clause and what to where-clause

    Hello,
    we currently have a discussion about the ANSI SQL Syntax where we do not agree what belongs to the join clause and what belongs to the where clause in an ANSI Sytnax SQL Query.
    Lets say there is a query like this:
    +SELECT *+
    FROM employees emp, departments dept
    WHERE emp.dept_country = dept.dept_country
    AND emp.dept_name = dept.dept_name
    AND dept.dept_type = 'HQ'
    AND emp.emp_lastname = 'Smith'
    Primary key of the departments table is on the columns dept_country, dept_name and dept_type. We have a Oracle database 10g.
    Now I have rewritten the query to Ansi Syntax:
    +SELECT *+
    FROM employees emp
    JOIN departments dept
    ON emp.dept_country = dept.dept_country AND emp.dept_name = dept.dept_name
    WHERE dept.dept_type = 'HQ'
    AND emp.emp_lastname = 'Smith'
    Another developer says that this is not completely correct, every filter on a column that belongs to the primary-key of the joined table has to be in the join clause, like this:
    +SELECT *+
    FROM employees emp
    JOIN departments dept
    +ON emp.dept_country = dept.dept_country AND emp.dept_name = dept.dept_name AND dept.dept_type = 'HQ'
    WHERE emp.emp_lastname = 'Smith'
    Can somebody tell me which on is correct?
    Is there any definition for that? I couldn't find it in the Oracle Database definition.
    I just found out the names of the ANSI documents here: http://docs.oracle.com/cd/B19306_01/server.102/b14200/ap_standard_sql001.htm#i11939
    I had a look at the ANSI webstore but there you have to buy the PDF files. In my case thats exaggerated because both of the Queries work and i am just interessted if there is one correct way.
    Thank you in advance
    Marco

    Hi,
    As i guideline i would say, answer the question: should the result of the join be filtered or should only filtered rows be joined from a particular table?
    This is helpful in the case of outer joins also, for inner joins it doesnt matters as said already be former posters, where there may be hughe semantical differences depending of where the predicates are placed.
    From performance view, if we talk about oracle, take a look a the execution plans. You will see that there is (probably) no difference in case of inner joins. Even in case of outer joins the optimizer pushes the predicate as a filter towards the table if it semantically possible.
    Regards

  • SQL syntax error...

    SQL Syntax:
    select ename||'-'||job from emp
    Initially, I was using the .Net Framework Data Provider for Oracle and had no problem bringing up the Query Builder in VS 2008. However, when I use the ODP .Net from Oracle, I get an error when bringing up the Query Builder:
    Error in SELECT clause: expression near '|'.
    Unable to parse query text.
    It seems like when uing ODP .Net, it does not like the concatenation in the Select statment.
    Any clue why?

    Is this consistently reproducible for you? Is it query builder specific? What version of ODP are you using? I just tried this with 11.1.6.20 ODP and it worked fine..
    Cheers
    Greg
    using System;
    using System.Data;
    using Oracle.DataAccess.Client;
    class Program
        static void Main(string[] args)
            using (OracleConnection con = new OracleConnection("data source=orcl;user id=scott;password=tiger"))
                con.Open();
                using (OracleCommand cmd = new OracleCommand("select ename||'-'||job from emp", con))
                    Console.WriteLine(cmd.ExecuteScalar().ToString());
    }

  • CR2011 - SQL Syntax Error

    After updating our ODBC driver to match our current Unidata database version (7.1), we now get the following message from Crystal Reports 2011 on many of our existing reports:
    "Failed to retrieve data from the database. Details: 37000:[Rocket U2][U2ODBC][1401249]Error ID: 21 Severity: ERROR Facility: DBCAPERR - SQL Syntax error. [Database Vendor Code: 5365440]
    The generated SQL statement follows:
    SELECT "INVCDETH_NF"."ITEM_NBR", "ITEMMAST_NF"."ITEM_DESC", "INVCDETH_NF"."SHIPPED_QUANTITY", "INVCDETH_NF"."Z_INV_DATE", "INVCDETH_NF"."Z_COMPANY", "INVCHDRH_NF"."INVOICE_TYPE", "INVCDETH_NF"."EXTENDED_PRICE", "INVCDETH_NF"."COST_OF_SALES", "INVCDETH_NF"."Z_PCC_CODE", "INVCDETH_NF"."DISCOUNT_AMOUNT", "INVCDETH_NF"."WAREHOUSE", "ITEMMAST_NF"."PRICE_CODE", "INVCHDRH_NF"."INVOICE_NBR", "INVCHDRH_NF"."REFERENCE_NBR"
    FROM   ("Administrators"."ITEMMAST_NF" "ITEMMAST_NF" INNER JOIN "Administrators"."INVCDETH_NF" "INVCDETH_NF" ON "ITEMMAST_NF"."ITEM_NBR"="INVCDETH_NF"."ITEM_NBR") INNER JOIN "Administrators"."INVCHDRH_NF" "INVCHDRH_NF" ON ((("INVCDETH_NF"."INVOICE_NBR"="INVCHDRH_NF"."INVOICE_NBR") AND ("INVCDETH_NF"."INV_HEADER_ID"="INVCHDRH_NF"."INV_HEADER_ID")) AND ("INVCDETH_NF"."REFERENCE_NBR"="INVCHDRH_NF"."REFERENCE_NBR")) AND ("INVCDETH_NF"."RELEASE_NBR"="INVCHDRH_NF"."RELEASE_NBR")
    WHERE  "INVCDETH_NF"."Z_COMPANY"='01' AND "INVCDETH_NF"."WAREHOUSE"='086' AND ("INVCDETH_NF"."Z_INV_DATE">={d '2013-12-08'} AND "INVCDETH_NF"."Z_INV_DATE"<={d '2013-12-26'})
    ORDER BY "INVCDETH_NF"."WAREHOUSE"
    I downloaded the trial version of CR2013 and get the same result. Can anyone shed any light? Thanks!

    Yes, in that the query is what Crystal generated from the report being built in the designer. I simply copied it from the Database > Show SQL Query screen. Since the error I'm receiving is a SQL Syntax Error, I thought it would be appropriate to show it.
    The bottom line is that because I am not very knowledgeable in SQL, I can't look at the query and identify the error. However, I am responsible for supporting CR in-house. Naturally, I have reported this to Rocket (the makers of the ODBC driver) but haven't received their reply yet.

Maybe you are looking for

  • Sync Send without a Exception Handler ??

    hi.. Can a synchronous send step work with out an exception handler..?? im gettin my messages and combinin then n sendin via the sync send to call rfc , followeed by a send back to my server.. at this very stage it expects me to define a handler for

  • My Macbook and Apple Service

    Well, my list of issues are: 1. Screen Mis-aligned when closed 2. 'Moo' noise 3. CPU temp hits 87 at load and sits at 67 (moo range) when idle. 4. CPU Whine which is only apparent on AC and can be stopped by opening photobooth or turning a core off/l

  • Why my Ipod won't work?

    I bought a iPod touch fifth generation august of 2014 haven't had any problems what so ever till maybe a few days ago when I asked my friend to put my iPod on the charger my iPod fell into a cup of his water I left it alone for a few days it won' eve

  • Invoice plan in PO

    Hii How the invoicing plan getting triggered in PO .?? What are major configuration has to be done for this invoicing plan in SPRO. Can some body explain me in depth reg this . Thanks

  • Input for Mobile Devices: Camera | ADC Presents | Adobe TV

    How can you take advantage of the camera integrated in most mobile devices?  Paul Trani shows you how to create an app that uses the native camera application. http://adobe.ly/wQqFu4