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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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)..
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
}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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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") ;
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
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();
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.
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
Table
is a reserved word, so in order to use it as a column name you need to enclose it in square brackets: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)..
i wrote follwing program in windows 7.
package jdbcodbcex;
import java.sql.*;
public class JdbcOdbcEx {
}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
You should to remove ) token in sql string like that -->
String sql="SELECT fname FROM person;"
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 .
PLEASE HELP ME !!!!!!!!!!!!!!!!!!!!!
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, seehttps://docs.oracle.com/javase/tutorial/jdbc/basics/prepared.html