Simple SQL syntax problem

Ok, I'm sure this is a very simple problem but I'm confused.
Statement s = con.createStatement();
s.execute("SELECT COUNT (*) FROM table WHERE id = 6 AND somechar = 'N'");java.sql.SQLException: Syntax error or access violation message from server: "You have an error in y
our SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax
to use near '(*) FROM table WHERE id = 6 AND somechar = 'N'' at line 1"
This works fine when input into the phpMyAdmin database interface. Is there something blatantly wrong with my syntax, or...?

Maybe it doesn't like the space between COUNT and (*)
%Yuck.
Yep, that was it. Thanks.
Weird, I'm accustomed to programs ignoring most whitespace as long as it doesn't create ambiguity.

Similar Messages

  • Oracle 9i Vs 10g Express Edition PL SQL syntax problem?

    The following code works perfectly on Oracle 9i , but fails in 10g Express Edition. Please help me figure out what the problem is
    product_master table exists and there is nothing wrong in there.The problem is a syntical one. Is there some 9i compatible mode? I'm using oracle express edition of 10 g. Login using the webbrowser. That itself is annoying.Why isnt there an SQL+ ide unlike 9i?
    Code :
    declare
    pd_no varchar2(6);
    cst number(8,2);
    begin
    pd_no:=&pd_no;
    SELECT cost_price INTO cst
    from product_master
    where product_no=pd_no;
    cst:=cst-200;
    IF cst >= 3000 THEN
    UPDATE product_master SET cost_price=cost_price-200
    WHERE product_no=pd_no;
    END IF;
    END;
    The error I get is
    ORA-06550: line 5, column 14:
    PLS-00103: Encountered the symbol "&" when expecting one of the following:
    ( - + case mod new not null
    avg
    count current exists max min prior sql stddev sum variance
    execute forall merge time timestamp interval date
    pipe
    3. cst number(8,2);
    4. begin
    5. pd_no:=&pd_no;
    6. SELECT cost_price INTO cst
    7. from product_master
    I changed & to : .The it asked for input but the following error came up
    ORA-06550: line 16, column 2:
    PLS-00103: Encountered the symbol ";"
    1. declare
    2. pd_no varchar2(6);
    3. cst number(8,2);

    One, possibility of occuring this error(PLS-00103) is, if you leave input without entering anything this will occur.
    Solution: Enter the value in quotation, like 'hello', below is one example which asks value for a, but i left it without entering any input, so the error occured.
    Once check out this in your case.
    SQL> @sample.sql
    Enter value for a:
    old   4: a:=&a;
    new   4: a:=;
    begin;
    ERROR at line 3:
    ORA-06550: line 3, column 6:
    PLS-00103: Encountered the symbol ";" when expecting one of the following:
    ( begin case declare exit for goto if loop mod null pragma
    raise return select update while with <an identifier>
    <a double-quoted delimited-identifier> <a bind variable> <<
    continue close current delete fetch lock insert open rollback
    savepoint set sql execute commit forall merge pipe purge
    SQL> spool off;

  • Simple SQL query problem

    Hi,
    I'm trying create a simple query which tells me the occurance of a particular football match on a particular date. The table is as follows...
    CREATE TABLE match
    (matchId NUMBER(5)
    CONSTRAINT match_matchId_nn NOT NULL,
    matchDate DATE
    CONSTRAINT match_date_nn NOT NULL,
    stadiumId          NUMBER(5)
    CONSTRAINT match_stadiumId_nn NOT NULL,
    CONSTRAINT matchId_pk PRIMARY KEY (matchId));
    Bascially, i'm trying to create a trigger which will implement the constraint that 'only one match can be at one stadium on a particular date'.
    Any ideas guys?
    Cheers...

    ALTER TABLE match ADD CONSTRAINT match_date_uk UNIQUE
    (stadiumId, matchDate)Bear in mind, though, that using dates in unique constraints can be problematic, because of the time element, which means there are 86400 unique values for each day. If your application enforces a rule that has only one match per stadium per day then all you need is a TRUNC() call in an insert/update trigger to make sure of that. If your application is going to allow more than one match per day the checking logic starts to get messy...
    Cheers, APC
    P.S. Oleg's solution is incorrect because it includes the primary key MatchId, which would thus permit duplicate combinations of stadium and date.

  • SQL syntax Problem

    let's say i want to get exactly the total service for an employee (how many years, how many months & how many days):
    the Appointment date is : 11/17/1992
    the Termination date is : 03/06/2001
    by using months_between it will be like this:
    select month_between(to_date('03/06/2001','MM/DD/YYYY'),to_date('11/17/1992','MM/DD/YYYY')) from dual;
    it will give exactly : 99.6451613 ,then
    we will divide it by 12 to get the years ,then we can truncate it to get the hole figure of the years, it will give exactly 8 years , my problem starts from here : how to get the months and the days?!!!!
    null

    Try this:
    select trunc(m/12) "Years", trunc(m-trunc(m/12)*12) "Months", (m-trunc(m))*31 "Days" from (select months_between(to_date('03/06/2001','MM/DD/YYYY'),to_date('11/17/1992','MM/DD/YYYY')) as m from dual where rownum=1)
    I did not check it (too many days to count :), but the results are reasonable.

  • Error when making connection:  You have an error in your SQL syntax;

    I'm getting this error when trying to make a simple Database Connection:
    SQLException: 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
    SQLState: 42000
    VendorError: 1064
    I tried a different driver and got the same error with more "?"s in the "use near....." part.
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.SQLException;
    public class DBTest{         public static void main(String[] args){                 try{                         Class.forName("com.mysql.jdbc.Driver").newInstance();                 } catch(Exception e){                         System.out.println(e);                         System.exit(0);                 }                 Connection conn = null;                 try {                         conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/testDB?" + "user=root&password=password");                         conn.close();                 } catch (SQLException ex) {                         // handle any errors                         System.out.println("SQLException: " + ex.getMessage());                         System.out.println("SQLState: " + ex.getSQLState());                         System.out.println("VendorError: " + ex.getErrorCode());                 }         } }
    MySQL Server Version:
    Server version: 5.0.67-0ubuntu6 (Ubuntu)

    cotton.m wrote:
    c0c0 wrote:
    I've tried Drivers 5.1 , 5.0 and 3.1 now and I get the same problem every time. I've tried switching databases, users, etc but always get this same error:
    java.sql.SQLException: 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
    I have the latest version of mysql from the Ubuntu repositories. Do I have to configure that a certain way? It isn't the URL which I supply that it does not like because I've tried multiple URLs and they all give me the same error when I supply the correct information.
    Any help is greatly appreciated.This is.. very odd.
    I have to ask are you really, really sure that your code is just as you posted? Are you sure you aren't running a query of some sort? My guess at this point would be some sort of rather bizarre encoding issue. I'm sorry but I can't reproduce your behaviour, I am connecting to different MySQL instances with no problem from Ubuntu..
    Yes the code is exactly the same as what I posted (except hiding actual usernames and passwords)
    I've even tried to connect to a remote mysql server and get the same behavior (If I type in the wrong database it alerts me there is no db of that name, if I lg in with the wrong password it alerts me cant login ____ @ ______, when I have all the correct information I get that same old error) , I'm somewhat convinced it's my driver now. I thought at first it was the way I had mysql configured but now I think it's my driver or the way I have everything installed. I simply put the driver location in the classpath and do the command:
    export set CLASSPATH=/usr/share/tomcat5.5-webapps/ROOT/lib/mysql-connector-java-5.1.7-bin.jar
    Was this the wrong way to go about doing it? I'm not currently running tomcat I simply put it there because a book said that's where it should go for tomcat, but I wanted to first try this not running tomcat with just a simple normal Java example.

  • Can anyone tell me what is wrong with the simple sql?

    Hi,
    I have a simple SQL (see attached). It returns records when it does not include the Order By sorting clause. However, if it includes the Order By clause, Oracle says no data found. Anyone can give me some ideas what could cause the problem?
    Thanks in advance.
    SELECT ih.item_key, e.episode_key, e.episode_date, wp.work_package_key, p.patient_name, c.codes_key
    FROM work_package wp, episodes e, item_header ih, patients p, codes c, station_element se, station_data sd
    WHERE wp.work_item_key = e.episode_key
    and e.episode_key = ih.item_key
    and ih.logical_parent_key = p.patient_key
    and e.episode_type = c.code_value
    and wp.asgn_station_key = se.item_key
    and se.station_name like 'DICT FIX%'
    and sd.station_key = wp.asgn_station_key
    and (sd.facility = '0' or sd.facility = 1)
    and wp.on_hold <> 'Y' and c.code_type = 'CEPT'
    and c.setup_group = 1
    ORDER BY e.episode_date, e.medrec_no;

    Hmmm...can you post a SQL Plus session that demonstrates this?

  • 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 Developer Problems and Feature Requests

    I’m in the process of comparing TOAD to SQL Developer and noticed the following bugs/features in SQL Developer:
    1. An error message is correctly displayed when a database password has expired, but there isn’t a way to go back into the database and change the password for that account. Can this critical feature be added?
    2. There is no option to connect as sysdba or sysoper.
    3. In the “New / Select Database Connection” window, I get the following error when double clicking on an existing connection defined using a TNS Network Alias: Status: Failure – no ocijdbc10 in java.library.path. Any ideas? Connection was initially defined using the Network Alias button. I can connect under the “Connections” window, but not in the “New / Select Database Connection” window. Any ideas?
    4. When displaying data in a table, the filter is not user friendly. You need to enter column names and the correct SQL syntax. It also does not allow you to cut and paste in column names. It would be very helpful/useful if it was more user friendly (GUI based) such as how Sorting is done and/or how it is done in TOAD.
    5. When viewing referential constraints on a child table, it shows you information on the parent, but not if the parent is a child to something else. If you were a parent, it would be nice to see all child and their children’s children. TOAD does a nice job showing parent and child tables via a tree structure.
    6. Comparing metadata between schemas would also be a very nice feature.
    I’m not sure if this is the place to post this but thought I would start here. Any feedback would be appreciated.
    Thanks,
    Ken

    1: You can always right click and have it open an sql*plus window and that will prompt for the new password. But I do agree that support for this should be built in.
    2: This is a developer tool.. Use OEM for the dba stuff. I think that the worst thing that could happen to SQL Dev is to try to become everything for everyone like TOAD tries to.
    3: Search the forum. Other users ran into this and I believe there is a workaround.
    4: I like the current filtering on tables. So much simpler than most tools. I do agree that maybe there should be an advanced button with a filter builder and agree that column names should be copyable but would cringe if the free-form field disappeared. How many other tools can you write an inline query into the table viewer? Great feature IMHO
    Eric

  • 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

  • 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());
    }

  • Simple SQL query statement is needed

    I need a simple SQL query to fetch records which is existed in all the departments.
    for example: i want to list the employees which are existed in each and every department.. not sure how should i get those.. will anyone help me please.. thanks in advance

    I think it would be wise to go to the following training:
    Oracle Database <version> : Introduction to SQL
    You will get the information you are looking for in five days. You can go find a tutorial on ANSI SQL, as advised by this board for free, to fix your immediate problem with a simple query. But, I personally recommend a more formal class specific to Oracle, as you will also get information about PL/SQL, and you get the benefit with working with other DBA/programmers when you are learning. This will solve your immediate issue, and any future issues with the language.
    You can find it in the Education section of the Oracle website.

  • Sql syntax inside java

    I am having a terrible time with the sql syntax INSIDE a java program. Is there somewhere online that has this information (in easy english!) For example I am trying to insert information in an access table. This is my sql query that works in access. How do I change the syntax to place it into java?
    INSERT INTO reservations ( fromcity, tocity, fromdate, todate, air, hotel, rental, airticketamt, hotelamt, rentalamt, customerId )
                   VALUES ('Seattle', 'Phoenix', #1/1/2002#, #2/2/2002#, yes, yes, yes, 50, 50, 50, 'CUST001');
    I also need to change the actual values (Seattle, etc) to the variables which is also a syntax problem!

    Here is a slightly smaller example of building the SQL. I didn't compile this so the syntax may not be 100%, but I think you can figure out the rest from this example.
    // Seed the String values for the convenience of the example
    String fromCity = "St. Paul";
    String toCity   = "Chicago";
    String fromDate = "#1/1/2002#";
    String toDate   = "#2/2/2002#";
    // Build the SQL using the String Values, the trick is to be
    // sure you have the appropriate spaces in the SQL when done,
    // and that you should use single tick marks to surround String
    // values
    String sql = "INSERT INTO reservations (fromCity, toCity, fromDate, toDate) " +
                    "VALUES ('" + fromCity + "', " +
                             "'"+ toCity   + "', " +
                             "'"+ fromDate + "', " +
                             "'"+ toDate   + "')";
    // Take a look at what was generated
    // to be sure it is what you want
    System.out.println(sql);                                 

  • Question about SQL syntax

    Hi,
    I am trying to create a very simple SQL Expression, but can't seem to get the syntax to be valid.  The database connection is to a SQL Server database. If I were to create the query in SQL Server Management Studio, it would be something like
       select LastName from People
    However, every variant I can think of, based on various examples in books and on-line postings, fails syntax check.  These include, among many others:
    select "People"."LastName"
    from "People"
    select "People"."LastName"
    from "PiapDB_ss5"."dbo"."People"
    I have also tried single quotes instead of double quotes.   I keep getting the same error: 
    Database Connector Error: '42000:[Microsoft][ODBC SQL Server Driver][SQL Server] Invalid syntax near the keyword 'select'.  [Database vendor code: 156].
    Any suggestions as to the proper syntax?
    Thanks.
    Dan

    an sql expression field is meant to return one value, not records. therefore using a "select * from ..." statement won't work. if you know the select statement will return one value only (e.g. select name from table where id=123), you can surround the statement with parenthesis, that should work.

  • ANSI SQL syntax?

    Hi all,
    I have a simple query
    SELECT A.*, B.Dstrct_Code FROM MSF601 A, MSF600 B
    WHERE ALTERNATE_REF LIKE 'PF%'
    AND A.alt_ref_code = B.Equip_No
    AND B.Dstrct_Code = 'ACME';
    which works fine, but I want to convert it to ANSI
    SQL syntax, so I tried
    SELECT A.*, B.Dstrct_Code FROM MSF601 A, MSF600 B
    WHERE ALTERNATE_REF LIKE 'PF%'
    INNER JOIN ON A.alt_ref_code = B.Equip_No
    AND B.Dstrct_Code = 'ACME';
    but I get
    ERROR at line 3:
    ORA-00933: SQL command not properly ended
    Could some kind soul explain why?
    Paul...

    An example that looks a lot like your example:
    SQL> select dept.*
      2       , emp.ename
      3    from dept, emp
      4   where dept.dname like '%A%'
      5   inner join on dept.deptno = emp.deptno
      6     and emp.sal > 1000
      7  /
    inner join on dept.deptno = emp.deptno
    FOUT in regel 5:
    .ORA-00933: SQL command not properly ended
    SQL> select dept.*
      2       , emp.ename
      3    from dept
      4         inner join emp on dept.deptno = emp.deptno
      5   where dept.dname like '%A%'
      6     and emp.sal > 1000
      7  /
                                    DEPTNO DNAME          LOC           ENAME
                                        30 SALES          CHICAGO       ALLEN
                                        30 SALES          CHICAGO       WARD
                                        20 RESEARCH       DALLAS        JONES
                                        30 SALES          CHICAGO       MARTIN
                                        30 SALES          CHICAGO       BLAKE
                                        10 ACCOUNTING     NEW YORK      CLARK
                                        20 RESEARCH       DALLAS        SCOTT
                                        10 ACCOUNTING     NEW YORK      KING
                                        30 SALES          CHICAGO       TURNER
                                        20 RESEARCH       DALLAS        ADAMS
                                        20 RESEARCH       DALLAS        FORD
                                        10 ACCOUNTING     NEW YORK      MILLER
    12 rijen zijn geselecteerd.Regards,
    Rob.

  • Entry-SQL syntax error: CASE not allowed

    Hello All. When I use sap netweaver developer to develop webdynpro applications, I always meet that jdbc error.
    when using inner join,left join, or using case when in the sql, it will pop up Entry-SQL syntax error.
    But I have run the sql in Microsoft SQL Server studio successfully.
    The SQL statement "UPDATE SAPNWDDB.Z_SERIAL SET LASTSERIAL = CASE WHEN ENDWITH IS NOT NULL THEN CASE WHEN LASTSERIAL + 1 > ENDWITH THEN ISNULL(STARTWITH, 0) ELSE LASTSERIAL + 1 END ELSE LASTSERIAL + 1 END WHERE SERIALNO = ?" contains the syntax error[s]: - 1:43 - Entry-SQL syntax error: CASE not allowed
    - 1:78 - Entry-SQL syntax error: CASE not allowed
    - 1:124 - SQL syntax error: the token "(" was not expected here
    Can someone help me? Thank you.

    Hi Arun Jaiswal ,
    Thank you for your answer. But I have tried query in sql editor. Actually it can work. Other than "CASE" syntax, it seems not support inner join and left join in webdynpro either. I even can not query the db views.
    That's imposible jdbc not support these simple syntex. I wonder there is any config control the sql compatibility level.
    I have developped a java programm to test it. It is ok. No error. But the same case pop up error in java webdynpro application.I don't know why.
    I am entry level webdynpro developper.
    Hopefully you can help me.
    Thank you.
    Edited by: zegunlee330 on Sep 3, 2010 4:18 AM

Maybe you are looking for

  • Max no.of zip attachments & recipents thru FM:SO_NEW_DOCUMENT_ATT_SEND_API1

    Hi, I want to know what is the number of attachments we can send thru FM:"SO_NEW_DOCUMENT_ATT_SEND_API1". I have 6 files, so i want to zip them all and send them all to atleast 20 mail recipients. I know way to check my doc size using: DOC_CHNG-DOC_S

  • Hr-abap payroll

    hi, plz  let me know how to exclude one person and run payroll, explain process flow . Thanks&Regards vijaya.m

  • Changing Oracle Home in unix

    Hi Experts, How can we change Oracle_Home in unix ? Db version : 9.2 patch (9.2.0.8) Any ideas....... Thanks & Regards, MB

  • LinkageError loader constraints

    I am trying to use XPathAPI in my program and the server is generating an error of: javax.faces.el.EvaluationException: java.lang.LinkageError: loader constraints violated when linking org/apache/xpath/objects/XObject class Any help would be apprecia

  • Administer Websites grayed out

    I am trying to be the administrator of a web site. The client has contribute and so do I. They already have a role as publisher, on their computer. I am trying to get her to make me a key to be administrator, but I am not sure what to tell her. How c