Hi all -
New SAS user here. I have a SAS Data Set that I want to read into a Java program and I'm currently hoping to approach this with a SAS Driver for JDBC (Looking into IOM driver before SAS/SHARE driver).
I've been referencing the SAS® 9.4 Drivers for JDBC: Cookbook. This is my code (copied from this page of the JDBC notebook😞
import java.sql.*; import java.util.Properties; public class AccessSASData { public static void main(String argv[]) { Connection connection; Properties props; int i; Statement statement; String queryString = "SELECT sup_id, sup_name " + "FROM mySasLib.suppliers ORDER BY sup_name"; ResultSet result; double id; String name; try { //CONNECT TO THE SERVER BY USING A CONNECTION PROPERTY LIST Class.forName("com.sas.rio.MVADriver"); props = new Properties(); props.setProperty("user","jdoe"); props.setProperty("password", "4ht8d"); props.setProperty("librefs", "mySasLib c:\\sasdata';"); props.setProperty("user","sasadm"); props.setProperty("password", "password"); props.setProperty("librefs", "mySasLib '/home/sas/pruebaint';"); connection = DriverManager.getConnection( "jdbc:sasiom://c123.na.abc.com:8591", props); //ACCESS DATA statement = connection.createStatement(); result = statement.executeQuery(queryString); while (result.next()){ id = result.getDouble(1); name = result.getString(2); System.out.println(id + " " + name); } statement.close(); connection.close(); } catch(Exception e){ System.out.println("error " + e); } } }
I copied sas.core.jar into my Eclipse project, but am getting a java.lang.ClassNotFoundException: com.sas.rio.MVADriver. What else do I need to do to even just load the driver class?
I found this post somewhat helpful, but it didn't resolve my problem.
You may find this other post here helpful, and I do list there the minimum set of jar files to use the MVA driver for JDBC.
Seems like a classpath issue - can you give more details about what you mean by copying the jar into your project? Did you add it to your build path as an external jar? You could test to see if you can "open" the MVADriver type (ctrl + shift + t, does eclipse recognize it as a valid class)
So yes, I added the jar (found in my SAS installation directory) to the build path as an external archive.
Eclipse does not recognize MVADriver as a valid class, which isn't too surprising to me because it also looks like sas.core.jar doesn't actually include com.sas.rio:
Is it possible that I'm using the wrong jar file?
I'd add sas.svc.connection.jar, and possibly the others on that list.
You may find this other post here helpful, and I do list there the minimum set of jar files to use the MVA driver for JDBC.
Hi, I am new to SAS, and trying to implement this example. It seems that you must have a SAS Share server up in order to use the jdbc driver in java code. Is this true? I would ideally like to read the contents of the SAS file without having a server up, rather just access the sas file locally. Is this possible? Can anyone shed light on this?
Thanks!
This is an older thread and I don't believe it's being monitored any longer. I highly recommend you post your question on either the Administration or SAS Programming board and reference this thread.
Thanks,
Joe
Join us for SAS Community Trivia
SAS Bowl XLII, SAS Hackathon 2024
Wednesday, August 14, 2024, at 10 a.m. ET | #SASBowl
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Select SAS Training centers are offering in-person courses. View upcoming courses for: