1

I am totally new to Unidata. I am trying to write a Java application that can query records from Unidata. I downloaded U2 Clients package and installed UniDK. I followed this example. I was able to get a single record by key/ID from the file in Unidata using the libraries in asjava.zip.

I came across the U2 Clients documentation which suggests about using JPA. I am wondering if there is any other options that I can write database query to get list of records with WHERE condition without implementing JPA. I am looking for something similar with using Php to write MySQL query.

Thanks.

Jia-Luo
  • 3,023
  • 5
  • 16
  • 17

3 Answers3

3

A late followup to a good answer: if you have a unidata programmer on staff, it may be better to make a call to a subroutine where you just pass parameters to get what you need. Sort of like calling a stored procedure in other languages. It's not a requirement at all, but it can be a good approach of you have a java programmer and a unidata/pick programmer working together on a project...

Ian McGowan
  • 3,461
  • 3
  • 18
  • 23
2

If you are going to need to access the Unidata database from Java on a regular basis, there is a product from Rocket (the owners of Unidata) called "UniObjects for Java" which comprises a class library to access Unidata, including logging in, performing queries and calling BASIC subroutines. Most developers I have worked with who need to do this use this product.

https://docs.rocketsoftware.com/nxt/gateway.dll/RKBnew20/unidata/previous%20versions/v7.2/unidata_uniobjectsjavadevguide_v72.pdf

1

Yes you can. First you will want to learn a little bit about 'UniQuery', which is the UniData database's query langauge. You can find that in the manuals on the Rocket Software site.

As an example, let's say you have a file called customers and fields called name and `age1

SELECT customers WITH name LIKE "Dan..." AND age GT "20"

This select statement will generate a list of record IDs that have a name starting with Dan and have an age greater than 20.

In your code, you will need to execute the SELECT statement first. Assuming udSess is the session you created:

UniCommand cmd = udSess.command(); // Create an object to run the command
cmd.setCommand("SELECT customers WITH name LIKE 'Dan...' AND age GT '20'")
cmd.exec()

UniSelectList sl = udSess.selectList(0);

while (!sl.isLastRecordRead())
{
   UniString recordID = sl.next();
   // Read your record here, using recordID
}
Dan McGrath
  • 41,220
  • 11
  • 99
  • 130
  • No problem. At this point, UniCommand. We do have a native UniJPA driver, but unfortunately it only works on Java 6 at this time. We are working on making it work for Java 7. – Dan McGrath Jun 28 '13 at 17:57
  • I see...I was trying out cmd.setCommand("LIST CUSTOMER");. It didn't work. Does UniCommand only work with 'SELECT' or do I need to plugin additional libraries? – Jia-Luo Jun 28 '13 at 20:11
  • I tried to query NAME, CITY from CUSTOMER table using UniCommand. Unicommand's reponse is empty. Am I missing anything here? Thanks. – Jia-Luo Jun 28 '13 at 22:16
  • After `exec`, if you do `String s = cmd.response();` you should get the response. Having said that, it would be strange using LIST in a non console application. – Dan McGrath Jun 28 '13 at 23:57
  • yeah...i was able to print out `cmd.response()`. However, how can I parse this string of response into an array or a dictionary? OR can I use SELECT to get attribute values? But I was reading through the UniQuery, I did not find anywhere that suggests SELECT can return a selection of attribute values. I was thinking if I should SELECT which returns a list of record ID, loop through the list of ID, and find the relevant attribute values using `unifile.read(key)` to get the fields of each record. But I find this inefficient. Do you have any recommendation on how I can approach this? – Jia-Luo Jun 29 '13 at 04:09
  • Yes you can. Look at the UniQuery command Reference Manual for the `BSELECT` verb. Alternatively, type `HELP BSELECT` at the command prompt – Dan McGrath Aug 07 '13 at 13:53