Background documentationExample: HelloMaxDB Locate this document in the navigation structure

 

The following example shows the source code of the HelloMaxDB Java class.

The individual steps are listed in the comments in the example.

HelloMaxDB.java

Syntax Syntax

  1. import java.sql.*;
    public class HelloMaxDB
    {
    	public static void main(String[] args)
    	throws ClassNotFoundException, SQLException
    	{
    		String username = "MONA";
    		String password = "RED";
    		String host = "";
    		String dbname = "DEMODB";
    
    		/*
       * Load JDBC Driver
       */
    		Class.forName ("com.sap.dbtech.jdbc.DriverSapDB");
    
    		/*
       * Define Connection URL
       */
    		String url = "jdbc:sapdb://" + host + "/" + dbname;
    
    		/*
       * Connect to the Database
       */
    		Connection connection = DriverManager.getConnection (url, username, password);
    
    		/*
       * Execute SQL Statements
       */
    		Statement stmt = connection.createStatement ();
    		ResultSet resultSet = stmt.executeQuery ("SELECT * FROM HOTEL.CUSTOMER");
    		resultSet.next ();
    		String hello = resultSet.getString (1);
    		System.out.println (hello);
    
    		/*
    		* close all objects
       */
    		resultSet.close ();
    		stmt.close();
    		connection.close ();
    		}
    }
    
End of the code.