• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

problem in type casting

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And welcome to the Ranch
 
That's a very big dog. I think I want to go home now and hug this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic