BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Truppip
Calcite | Level 5

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.

1 ACCEPTED SOLUTION

Accepted Solutions
FriedEgg
SAS Employee

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.

 

https://communities.sas.com/t5/Developers/How-can-I-use-SAS-9-4-jdbc-driver-in-the-Spring-boot-appli...

 

View solution in original post

6 REPLIES 6
dpage
SAS Employee

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)

Truppip
Calcite | Level 5

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: 

jar-contents.PNG

 

Is it possible that I'm using the wrong jar file? 

 

dpage
SAS Employee

https://go.documentation.sas.com/?docsetId=jdbcref&docsetTarget=n0b06dcgstvo22n11rtu017ghbi6.htm&doc...

 

I'd add sas.svc.connection.jar, and possibly the others on that list. 

FriedEgg
SAS Employee

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.

 

https://communities.sas.com/t5/Developers/How-can-I-use-SAS-9-4-jdbc-driver-in-the-Spring-boot-appli...

 

dweltman
Calcite | Level 5

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! 

joeFurbee
Community Manager

@dweltman.,

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 XLIII, The New SAS Developer Portal
Wednesday, August 14, 2024, at 10 a.m. ET | #SASBowl

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 6524 views
  • 0 likes
  • 5 in conversation