aspose file tools*
The moose likes JDBC and the fly likes sqlException column not found Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "sqlException column not found" Watch "sqlException column not found" New topic
Author

sqlException column not found

numan ahmad
Ranch Hand

Joined: Jan 27, 2011
Posts: 49
i want to make connection with my database just want to print all records, for this purpose i wrote a query like that



String driver="sun.jdbc.odbc.JdbcOdbcDriver";
Class.forName(driver);

String db="jdbcdbc:database1";
con=DriverManager.getConnection(db);
st=con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql="select * from customer,product,inventry,accounts";
rs=st.executeQuery(sql);


it give me sql exception error..i want to know that is it rite way to write query if not then what should be rite?
i search a lot on Google but did not succeed please help me and thanks in advance ..
Vijay Tidake
Ranch Hand

Joined: Nov 04, 2008
Posts: 146

Hi,

will you please provide some stackstrace of the sqlException.

Thanks


The important thing is not to stop questioning.Curiosity has its own reason for existing.
numan ahmad
Ranch Hand

Joined: Jan 27, 2011
Posts: 49
SQLException: column not found

at jdbc.odbc.jdbcodbcResultSet.find column(jdbcodbcResultSet.java:180)

at jdbc.odbc.jdbcodbcResultSet.getString(jdbcodbcResultSet.java:411)
Vijay Tidake
Ranch Hand

Joined: Nov 04, 2008
Posts: 146

Hi,

I this the error is in query.Please check it.

select * from customer,product,inventry,accounts

Thanks
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18651
    
    8

Yes, that was numan's question... "What is wrong with this query?"

My question is, what is the query supposed to do? To me it looks like a four-way Cartesian product of four unrelated files. That wouldn't be a good idea so there isn't much point in trying to make it work.
Vijay Tidake
Ranch Hand

Joined: Nov 04, 2008
Posts: 146

Sorry Paul..
I didn't get you.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18651
    
    8

It's just that since numan said
i want to know that is it rite way to write query if not then what should be rite?

I didn't think that just telling him/her to check the query was very helpful. He/she already knew there was a problem with it, and wanted to know what the problem was.

(However I don't know what the problem is either, so perhaps my answer didn't help much. And then numan is using MS Access, which is well-known for providing useless error messages like that one...)
Vijay Tidake
Ranch Hand

Joined: Nov 04, 2008
Posts: 146

Ok..got it
thanks for suggestion
numan ahmad
Ranch Hand

Joined: Jan 27, 2011
Posts: 49
sorry i did not get you paul would you explain it more ?
numan ahmad
Ranch Hand

Joined: Jan 27, 2011
Posts: 49
i want to retrieve data from multiple tables...the query that i wrote is it rite or not if not then please tell me the correct way to retrieve data ?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18651
    
    8

I don't know. Normally to select data from several tables you would do some kind of a join. If you really want to do the four-way cartesian product then you might have to do something different.

For example if two tables had a column with the same name, you might not be able to use "Select *" in that case. You might have to specify the names of the columns you want, complete with prefix to indicate which table they were coming from.

However I still advise you to start with a reasonable query. Trying to learn SQL from bad ideas is not a good approach.
numan ahmad
Ranch Hand

Joined: Jan 27, 2011
Posts: 49
hmmmmm ok thanks a lot....
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: sqlException column not found