wood burning stoves 2.0*
The moose likes JDBC and the fly likes Microsoft Access Store Query Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Microsoft Access Store Query" Watch "Microsoft Access Store Query" New topic
Author

Microsoft Access Store Query

Allen Tomas
Greenhorn

Joined: Apr 15, 2004
Posts: 4
I am sure someone ask this question before but I can not find the topic using the searsh soooooo....
Would anyone know how to access a stored query in Microsoft Access using the ODBC-JDBC?
Thank you in advance.
Blake Minghelli
Ranch Hand

Joined: Sep 13, 2002
Posts: 331
You can select rows from an Access query just like you would select from an Access table. For example, once you have your Connection object you can do something like this:


Blake Minghelli<br />SCWCD<br /> <br />"I'd put a quote here but I'm a non-conformist"
Allen Tomas
Greenhorn

Joined: Apr 15, 2004
Posts: 4
Thank you for replying.
However, I was actually looking helping in accessing a pre-defined query in access using jdbc connection. For example, in Access you could create a query and save as (for argument sake) myquery. Then in my java code, I want to access that query "myquery" and process it. It is sort of like a stored procedure in SQL Server.
Allen
Blake Minghelli
Ranch Hand

Joined: Sep 13, 2002
Posts: 331
Originally posted by Allen Tomas:
Thank you for replying.
However, I was actually looking helping in accessing a pre-defined query in access using jdbc connection. For example, in Access you could create a query and save as (for argument sake) myquery. Then in my java code, I want to access that query "myquery" and process it. It is sort of like a stored procedure in SQL Server.
Allen

That's exactly what that code is doing, just replace "query1" with "myquery". The code above does however assume that the "stored" query is a "select" query. If it is not a "select" query, then you can do this:

I'm not sure though if you can pass parameters using that method, so if your Access query is expecting some params, it probably won't work. I don't believe PreparedStatement or CallableStatement are supported.
Blake Minghelli
Ranch Hand

Joined: Sep 13, 2002
Posts: 331
I'm not sure though if you can pass parameters using that method

Out of curiousity, I tried this and it worked:
Allen Tomas
Greenhorn

Joined: Apr 15, 2004
Posts: 4
Thank you so much Blake. I'm curious. How does your stored query look like when you are passing it a parameter?
[ April 22, 2004: Message edited by: Allen Tomas ]
Blake Minghelli
Ranch Hand

Joined: Sep 13, 2002
Posts: 331
Originally posted by Allen Tomas:
Thank you so much Blake. I'm curious. How does your stored query look like when you are passing it a parameter?
[ April 22, 2004: Message edited by: Allen Tomas ]

I'm not sure I understand what you are asking, but... I created a query in Access and in the query designer, I added "[Enter param]" in the "Criteria" row of one of the query's columns. When you run the query in Access, you get an InputBox that asks the user to "Enter param". But when you do the "exec myquery..." in Java it uses the param supplied in the exec string.
Does that help?
Allen Tomas
Greenhorn

Joined: Apr 15, 2004
Posts: 4
Yes, Thank you again. It works.
[ April 23, 2004: Message edited by: Allen Tomas ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Microsoft Access Store Query
 
Similar Threads
strange problem...help!!!!!
java database connectivity
Failed to load JDBC/ODBC driver.
java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Too few parameters.
Accessing Address Book