• Post Reply Bookmark Topic Watch Topic
  • New Topic

problem in type casting  RSS feed

 
albus black
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
im using java to build a project and im at beginner level in java so i encountered a problem

i am using gsql parser's java api to parse database queries and there is one little point where i have stuck up

there are 2 classes TSelectSqlStatement & TCreateTableSqlStatement both inherit TCustomSqlStatement class and i have to use a method in Createtable in SelectSql and when i do this type casting isnt allowed

is there any way to solve this problem??

link for the api reference is

http://www.sqlparser.com/kb/javadoc/

this is the DBSystem.java



this is the printSelect.java


This is the error when compiled

Exception in thread "main" java.lang.ClassCastException: gudusoft.gsqlparser.stmt.TSelectSqlStatement cannot be cast to gudusoft.gsqlparser.stmt.TCreateTableSqlStatement at dbs.printSelect.analyze(printSelect.java:43) at dbs.printSelect.main(printSelect.java:34) at dbs.DBSystem.analyzeSelectStmt(DBSystem.java:758) at dbs.DBSystem.analyzeStmt(DBSystem.java:364) at dbs.DBSystem.main(DBSystem.java:347)
 
Campbell Ritchie
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My, we aren't going to read all that code. The error message with the Exception is very specific and very clear. It tells you what you need to know. You are trying to cast something with is one type to another, and it isn't that other type. You can only cast reference types to the type they really are.
A gudusoft.gsqlparser.stmt.TSelectSqlStatement has never been a gudusoft.gsqlparser.stmt.TCreateTableSqlStatement and never will be, so you can't cast like that.
 
Campbell Ritchie
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to the Ranch
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!