Published 2021. 10. 15. 20:20
728x90
반응형

java 티베로 연결 예제

import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class TiberoTest{
	private String ip = "ip주소";
    private int port = 포트번호;
    private String database = "데이터베이스";
    private String user = "계정";
    private String password = "비밀번호";

    private final String DRIVER_NAME = "com.tmax.tibero.jdbc.TbDriver";
    private final String TIBERO_JDBC_URL = "jdbc:tibero:thin:@" + ip + ":" + port + ":" + database;

    private Connection conn = null;

    private void connect() {
        try {
        Class.forName(DRIVER_NAME);
            conn = DriverManager.getConnection(TIBERO_JDBC_URL, user, password);
        } catch(ClassNotFoundException e) {
            System.err.println(e);
        } catch(SQLException e) {
            System.err.println(e);
        }
    }

    private void executeQuery() {
        String sql = "select * from testTable";
        try {
            Statement stmt = conn.createStatement();
            ResultSet rs = stmt.executeQuery(sql);
            
            while(rs.next()) {
                System.out.println(rs.getString(1));
            }
        } catch(SQLException e) {
            System.err.println(e);
        }
    }
    
    private void disconnect() {
        if(conn != null) {
            try {
                conn.close();
            } catch(SQLException e) {
                System.err.println(e);
            }
        }
    }
    
	public static void main(String[] args) {
		TiberoTest tibero = new TiberoTest();

        tibero.connect();
        tibero.executeQuery();
        tibero.disconnect();
	}
}
반응형

'프로그래밍 > JAVA' 카테고리의 다른 글

ArrayList 사용 예제  (0) 2021.12.28
자바 Collection(List, Set, Map) 비교  (0) 2021.12.27
java file download  (0) 2021.10.14
UnknownHostException  (0) 2021.10.13
java url생성  (0) 2021.10.12
복사했습니다!