> For the complete documentation index, see [llms.txt](https://docs.tibero.com/tibero-manuals/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.tibero.com/tibero-manuals/7.2.5.manuals/tibero-development-guide/appendix-a.tbjdbc-example.md).

# Appendix A. tbJDBC 예제

## JdbcTest.class

다음은 tbJDBC를 이용하여 **JdbcTest** 클래스 파일을 작성한 프로그램 소스 코드입니다.

```
import java.sql.CallableStatement; 
import java.sql.Connection;
import java.sql.DriverManager; 
import java.sql.PreparedStatement; 
import java.sql.ResultSet;
import java.sql.SQLException; 
import java.sql.Statement; 
import java.sql.Types;

public class JdbcTest
{
    Connection conn;

    public static void main(String[] args) throws Exception
    {
        JdbcTest test = new JdbcTest();

        test.connect(); 
        test.executeStatement(); 
        test.executePreparedStatement(); 
        test.executeCallableStatement(); 
        test.disconnect();
    }

    private void connect() throws ClassNotFoundException
    {
        Class.forName("com.tmax.tibero.jdbc.TbDriver");

        try {
            conn = DriverManager.getConnection(
                    "jdbc:tibero:thin:@localhost:8629:tibero", "tibero", "tmax");
        } catch (SQLException e) {
            System.out.println("connection failure!");
            System.exit(-1);
        }
        System.out.println("Connection success!");
    }

    private void executeStatement() throws SQLException
    {
        String dropTable = "drop table emp";
        String createTable = "create table emp (id number, "+
                             " name varchar(20), salary number)";
        String InsertTable = "insert into emp values(1000, 'Park', 5000)";
        
        Statement stmt = conn.createStatement();
        
        try {
            stmt.executeUpdate(dropTable);
        } catch(SQLException e) {
            // if there is not the table
        }

        stmt.executeUpdate(createTable); 
        stmt.executeUpdate(InsertTable);

        stmt.close();
    }

    private void executePreparedStatement() throws SQLException
    {
        PreparedStatement pstmt = conn
                .prepareStatement("select name from emp where id = ?");

        pstmt.setString(1, "1000");

        ResultSet rs = pstmt.executeQuery();

        while (rs.next()) {
            System.out.println(rs.getString(1));
        }
        pstmt.close();
    }

    private void executeCallableStatement() throws SQLException
    {
        String callSQL = " CREATE PROCEDURE testProc "+
                         " (ID_VAL IN NUMBER, SAL_VAL IN OUT NUMBER) as " +
                         " BEGIN" +
                         " update emp" +
                         " set salary = SAL_VAL" +
                         " where id = ID_VAL;" +
                         " select salary into SAL_VAL" +
                         " from emp" +
                         " where id = ID_VAL;" +
                         " END;";

        String dropProc = "DROP PROCEDURE testProc";

        Statement stmt = conn.createStatement();
        
        try {
            stmt.executeUpdate(dropProc);
        } catch(SQLException e) {
            // if there is not the procedure
        }

        stmt.executeUpdate(callSQL);

        CallableStatement cstmt = conn.prepareCall("{call testProc(?, ?)}");
        cstmt.setInt(1, 1000);
        cstmt.setInt(2, 7000);
        cstmt.registerOutParameter(2, Types.INTEGER);
        cstmt.executeUpdate();

        int salary = cstmt.getInt(2);
        System.out.println(salary);

        stmt.close();
        cstmt.close();
    }

    private void disconnect() throws SQLException
    {
        if (conn != null) 
            conn.close();
    }
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.tibero.com/tibero-manuals/7.2.5.manuals/tibero-development-guide/appendix-a.tbjdbc-example.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
