Use the following example to find out how to connect to the database instance and then execute simple database queries. The individual steps are listed in the comments in the example.
import java.sql.*;
public class HelloSapDB {
public static void main (String [] args)
throws ClassNotFoundException, SQLException
{
String dbm_user = "TESTUSER";
String password = "TEST";
String database_server = "LOCALSERVER";
String database_name = "TST";
/*
*/
Class.forName ("com.sap.dbtech.jdbc.DriverSapDB");
/*
*/
String url = "jdbc:sapdb://" + database_server + "/" + database_name;
/*
* Call the java.sql.DriverManager.getConnection method
*/
Connection connection = DriverManager.getConnection (url, dbm_user, password);
/*
* Execute a database query; database queries are formulated in Structured Query Language (SQL).
*/
Statement stmt = connection.createStatement ();
ResultSet resultSet = stmt.executeQuery ("SELECT 'hello world' FROM dual");
resultSet.next ();
String hello = resultSet.getString (1);
System.out.println (hello);
/*
* Close all objects
*/
resultSet.close ();
stmt.close ();
connection.close ()
}
}