Menu

recreiving Error Message unexpected token: = required: (

2017-01-28
2020-07-20
  • Harry Knight

    Harry Knight - 2017-01-28

    I have a problem swith a simple query failing and giving th emessage "net.ucanaccess.jdbc.UcanaccessSQLException: UCAExc:::4.0.0 unexpected token: = required: ("
    I tried to post the entire code block here but it gets reformatted into intelligibility. The exceptiin was generated by the a PreparedStatement.preparation as Follows

    String Query = "SELECT * FROM PlayerNumbers WHERE Section = ? AND Table = ? AND Direction = ?;";
    pst = con.prepareStatement(Query);
    pst.setInt(1, 2);
    pst.setInt(2, 3);
    pst.setString(3, "S");
    recs = pst.executeQuery();

    The complete stack trace isa s follows. The reference UcanAccessProblem.java:82 points to the con.PrepareStatement above.
    

    I have a similar query to another table that is very similar and woks fine. I also tried taking out the ? and removing the set Parameter calls to no avail.. If I take out the "WHERE" clause the query works but is not of much use..
    Hs anybody encountered this problem ? It's a very simple query so I'm baffled as to why it won't run.

    Jan 27, 2017 9:40:42 PM UcanAccessProblem testSource
    

    SEVERE: null
    net.ucanaccess.jdbc.UcanaccessSQLException: UCAExc:::4.0.0 unexpected token: = required: (
    at net.ucanaccess.jdbc.UcanaccessConnection.prepareStatement(UcanaccessConnection.java:528)
    at UcanAccessProblem.testSource(UcanAccessProblem.java:82)
    at UcanAccessProblem.<init>(UcanAccessProblem.java:24)
    at UcanAccessProblem.main(UcanAccessProblem.java:99)
    Caused by: java.sql.SQLSyntaxErrorException: unexpected token: = required: (
    at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
    at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
    at org.hsqldb.jdbc.JDBCPreparedStatement.<init>(Unknown Source)
    at org.hsqldb.jdbc.JDBCConnection.prepareStatement(Unknown Source)
    at net.ucanaccess.jdbc.UcanaccessConnection.prepareStatement(UcanaccessConnection.java:525)
    ... 3 more
    Caused by: org.hsqldb.HsqlException: unexpected token: = required: (
    at org.hsqldb.error.Error.parseError(Unknown Source)
    at org.hsqldb.ParserBase.unexpectedTokenRequire(Unknown Source)
    at org.hsqldb.ParserBase.readThis(Unknown Source)
    at org.hsqldb.ParserDQL.XreadSimpleValueExpressionPrimary(Unknown Source)
    at org.hsqldb.ParserDQL.XreadAllTypesValueExpressionPrimary(Unknown Source)
    at org.hsqldb.ParserDQL.XreadAllTypesPrimary(Unknown Source)
    at org.hsqldb.ParserDQL.XreadAllTypesFactor(Unknown Source)
    at org.hsqldb.ParserDQL.XreadAllTypesTerm(Unknown Source)
    at org.hsqldb.ParserDQL.XreadAllTypesCommonValueExpression(Unknown Source)
    at org.hsqldb.ParserDQL.XreadBooleanPrimaryOrNull(Unknown Source)
    at org.hsqldb.ParserDQL.XreadBooleanTestOrNull(Unknown Source)
    at org.hsqldb.ParserDQL.XreadBooleanFactorOrNull(Unknown Source)
    at org.hsqldb.ParserDQL.XreadBooleanTermOrNull(Unknown Source)
    at org.hsqldb.ParserDQL.XreadBooleanValueExpression(Unknown Source)
    at org.hsqldb.ParserDQL.readWhereGroupHaving(Unknown Source)
    at org.hsqldb.ParserDQL.XreadTableExpression(Unknown Source)
    at org.hsqldb.ParserDQL.XreadQuerySpecification(Unknown Source)
    at org.hsqldb.ParserDQL.XreadSimpleTable(Unknown Source)
    at org.hsqldb.ParserDQL.XreadQueryPrimary(Unknown Source)
    at org.hsqldb.ParserDQL.XreadQueryTerm(Unknown Source)
    at org.hsqldb.ParserDQL.XreadQueryExpressionBody(Unknown Source)
    at org.hsqldb.ParserDQL.XreadQueryExpression(Unknown Source)
    at org.hsqldb.ParserDQL.compileCursorSpecification(Unknown Source)
    at org.hsqldb.ParserCommand.compilePart(Unknown Source)
    at org.hsqldb.ParserCommand.compileStatement(Unknown Source)
    at org.hsqldb.Session.compileStatement(Unknown Source)
    at org.hsqldb.StatementManager.compile(Unknown Source)
    at org.hsqldb.Session.execute(Unknown Source)
    ... 6 more

     
  • Gord Thompson

    Gord Thompson - 2017-01-29

    Table is a reserved word, so in order to use it as a column name you need to enclose it in square brackets:

    String sql = "SELECT * FROM PlayerNumbers  WHERE Section = ? AND [Table] = ?  AND Direction = ?;";
    PreparedStatement pst = conn.prepareStatement(sql);
    
     
    • Harry Knight

      Harry Knight - 2017-01-30

      Thank you so much for your help. One always feesl stupid when you fail to identify an obvious problem.The database I am extracting data from is not under my control and I had used SELECT * on it earlier to extract information which of course worked fine. The diagnostics are not overly helpful. Int the tbles I have developed I used the coumn name "TableNo" so I never encountered the problem. (TableNo refers to the taable number in a duplicate brisge session)..

       
  • adeeba almas

    adeeba almas - 2019-02-19

    i wrote follwing program in windows 7.
    package jdbcodbcex;
    import java.sql.*;

    public class JdbcOdbcEx {

    public static void main(String[] args) {
             try{
    Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
    String url="jdbc:ucanaccess://D:\\datedtuesday.accdb";
    Connection con=DriverManager.getConnection(url);
    Statement st=con.createStatement();
    String sql="SELECT fname FROM person)";
        preparedStatement pst=prepareStatement(sql);
    ResultSet rs=st.executeQuery(sql);
    while(rs.next()){
        String name=rs.getString("fname");
        String add=rs.getString("address");
        String pNum=rs.getString("phonenumber");
        System.out.println(name+add+pNum);
    }
    con.close();
    

    }catch(Exception ex){
    System.out.println(ex);
    }
    System.out.println("this is an output");
    }

    }
    above program is giving me this error.plz tell me how can i get rid of this error.
    net.ucanaccess.jdbc.UcanaccessSQLException: UCAExc:::4.0.4 unexpected token: )
    this is an output

    i am using java 8 and net beens 8 versions

     
  • Abdelrazek Nageh

    You should to remove ) token in sql string like that --> String sql="SELECT fname FROM person;"

     
  • shafay

    shafay - 2020-07-18

    guys please help me i have a problem , i dont know what this erorr means . if anybody knows please reply , i am new to oop language thats why help me .

    this is the code
    public void SaveToDatabase(String fName, String lName, Integer dob, String mob, Integer yob, String PassportNo , String email , double Contact, Integer age,String dep, String des)
    {
    try {
    Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
    Connection conn = DriverManager.getConnection("jdbc:ucanaccess://C://AIS_Ticket_Reservation_System//database//Database4.accdb");
    Statement st = conn.createStatement();
    String sr = ("INSERT INTO Booking"
    + "(firstname,lastname,dateofBirth,MonthOfBirth,YearOfBirth,PassportNumber,email,ContactInfo,age,Departure,Destination) " + "VALUES"
    + "('"+ fName +"','"+lName+"',"+dob+",'"+mob+"',"+yob+",'"+PassportNo+"','"+email+"',"+Contact+","+age+",'"+dep+"','"+des+"')");
    st.execute(sr) ;
    System.out.println("seuccsfull") ;

            I am saving this this items in data base , but i got erorr evey time , this save database method work , sometime it works fine , it is adedd but after doing 1 time , it started giving this type of erorr .
            erorr :- Exception: UCAExc:::5.0.0-SNAPSHOT unexpected token: Z_12312312E8 required: )
    

    PLEASE HELP ME !!!!!!!!!!!!!!!!!!!!!

     
  • Gord Thompson

    Gord Thompson - 2020-07-20

    Don't use string concatenation to inject data values into your SQL command. Do a web search for "SQL injection" to learn more about why that is considered bad practice.

    Instead, create your SQL command using parameter placeholders and use a PreparedStatement to execute the statement. For details, see

    https://docs.oracle.com/javase/tutorial/jdbc/basics/prepared.html

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.