티스토리 뷰

카테고리 없음

timeout 처리

진열사랑 2024. 8. 7. 18:31

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.boot.CommandLineRunner;

import org.springframework.boot.SpringApplication;

import org.springframework.boot.autoconfigure.SpringBootApplication;



import javax.sql.DataSource;

import java.sql.Connection;

import java.sql.SQLException;

import java.sql.Statement;



@SpringBootApplication

public class SpringBootPostgresApplication implements CommandLineRunner {



    @Autowired

    private DataSource dataSource;



    public static void main(String[] args) {

        SpringApplication.run(SpringBootPostgresApplication.class, args);

    }



    @Override

    public void run(String... args) {

        try (Connection connection = dataSource.getConnection()) {

            try (Statement statement = connection.createStatement()) {

                // Set statement_timeout to 30 seconds

                statement.execute("SET statement_timeout TO '30s'");

                // Now execute your query

                statement.execute("SELECT * FROM your_table");

            }

            System.out.println("Successfully executed the query!");

        } catch (SQLException e) {

            System.err.println("Failed to execute the query: " + e.getMessage());

        }

    }

}

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/02   »
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28
글 보관함