Open Source RDBMS - Seamless, Scalable, Stable and Free

한국어 | Login |Register

Versions available for this page: CUBRID 8.3.0 |  CUBRID 8.3.1 |  CUBRID 8.4.0 |  CUBRID 8.4.1 |  CUBRID 8.4.3 |  CUBRID 9.0.0 | 

Connecting to Other Database

You can connect to another outside database instead of the currently connected one even when the server-side JDBC driver is being used. Acquiring a connection to an outside database is not different from a generic JDBC connection. For more information, see JDBC API.

If you connect to other databases, the connection to the CUBRID database does not terminate automatically even when the execution of the Java method ends. Therefore, the connection must be explicitly closed so that the result of transaction operations such as COMMIT or ROLLBACK will be reflected in the database. That is, a separate transaction will be performed because the database that called the Java stored function/procedure is different from the one where the actual connection is made.

import java.sql.*;

public class SelectData {

  public static void SearchSubway(String[] args) throws Exception {

Connection conn = null;

  Statement stmt = null;

  ResultSet rs = null;

  try {


    conn =


    String sql = "select line_id, line from line";

    stmt = conn.createStatement();

    rs = stmt.executeQuery(sql);

    while( {

      int host_year = rs.getString("host_year");

      String host_nation = rs.getString("host_nation");

      System.out.println("Host Year ==> " + host_year);

      System.out.println(" Host Nation==> " + host_nation);






    } catch ( SQLException e ) {


    } catch ( Exception e ) {


    } finally {

          if ( conn != null ) conn.close();




When the Java stored function/procedure being executed should run only on JVM located in the database server, you can check where it is running by calling System.getProperty ("cubrid.server.version") from the Java program source. The result value is the database version if it is called from the database; otherwise, it is NULL.