wood burning stoves 2.0*
The moose likes JDBC and the fly likes use a database schema from java using jdbc Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "use a database schema from java using jdbc" Watch "use a database schema from java using jdbc" New topic
Author

use a database schema from java using jdbc

suman deb
Ranch Hand

Joined: Jul 14, 2005
Posts: 54
Hi all,

I am trying to execute a sql query from java using jdbc and its throwing me an db exception. here is the code -
----------------------------------------------------------------------------------------------
String query = "use primus \ngo\n";
query = query + "select o.name , text = convert(char(255) not null, text) " +
"from sysobjects o, syscomments s "+
"where o.type = 'P' and s.id = object_id(o.name) order by o.name";
PreparedStatement st = conn.prepareStatement(query);
ResultSet rs = st.executeQuery();
---------------------------------------------------------------------------------------------
and here is the exception -
SQL Exception:Incorrect syntax near 'go'.

But the same code is working when I am running it directly in the database.

Please help

Thanks
Suman
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30116
    
150

Suman,
That looks like two statements. Why not write it as one?

from primus.sysobjects o


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
jQuery in Action, 2nd edition
 
subject: use a database schema from java using jdbc
 
Similar Threads
JPA native query problem
Query works in DB, but not with JDBC (MS version)
"Select max version" query?
need help in EJB QL with upper and like
Why difference in result