Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Microsoft Access Store Query

 
Allen Tomas
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 331
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
 
Allen Tomas
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 331
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 331
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 331
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, Thank you again. It works.
[ April 23, 2004: Message edited by: Allen Tomas ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic