You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

本地通过Simba JDBC连接GCP BigQuery遇连接超时错误

解决Simba JDBC连接BigQuery时的HttpTransport超时问题

你遇到的[Simba][BigQueryJDBCDriver](100004) HttpTransport IO error : Error getting access token for service account: connect timed out错误,核心是本地无法通过网络获取服务账号的认证令牌,已排除权限问题的前提下,可按以下步骤排查解决:

1. 检查网络连通性与代理配置

  • 先验证本地网络能否访问Google OAuth2令牌端点:直接访问https://oauth2.googleapis.com/token,确认能正常打开(或用curl https://oauth2.googleapis.com/token测试)
  • 若处于公司内网/受限制网络,必须配置代理参数:
    // 添加代理配置
    ds.setProxyHost("你的代理地址");
    ds.setProxyPort(代理端口);
    // 若代理需要认证
    ds.setProxyUser("代理用户名");
    ds.setProxyPassword("代理密码");
    

2. 验证密钥文件路径与权限

  • 修正Windows路径格式:将反斜杠改为正斜杠,比如C:/Users/xx/UI/GCP/devgcp.json,避免转义错误
  • 确认本地用户拥有该JSON密钥文件的读取权限,防止因文件权限不足导致无法加载密钥发起认证

3. 调整超时参数与JDBC URL格式

  • 延长超时时间:当前设置的40秒可适当提升,比如ds.setTimeout(60000L);(60秒)
  • 简化JDBC URL:标准格式可整合ProjectId,避免重复配置:
    ds.setURL("jdbc:bigquery://www.googleapis.com/bigquery/v2:443;ProjectId=xxx;");
    

4. 检查驱动版本兼容性

  • 低版本Simba驱动可能存在网络适配问题,建议更新到官方最新版本,确保与GCP BigQuery API版本匹配

调整后的示例代码

import com.simba.googlebigquery.jdbc42.DataSource;
import java.sql.Connection;
import java.sql.SQLException;

public class TestConnection {
    public static void main(String[] args) {
        System.out.println("Connection check");

        Connection connection = null;
        DataSource ds = new com.simba.googlebigquery.jdbc42.DataSource();
        
        // 整合ProjectId的标准JDBC URL
        ds.setURL("jdbc:bigquery://www.googleapis.com/bigquery/v2:443;ProjectId=xxx;");
        ds.setOAuthPvtKeyFilePath("C:/Users/xx/UI/GCP/devgcp.json");
        ds.setOAuthType(0);
        ds.setOAuthServiceAcctEmail("xx@xx.gserviceaccount.com");
        // 延长超时至60秒
        ds.setTimeout(60000L);
        
        // 代理配置(按需启用)
        // ds.setProxyHost("your-proxy-host");
        // ds.setProxyPort(your-proxy-port);
        // ds.setProxyUser("proxy-user");
        // ds.setProxyPassword("proxy-password");

        try {
            connection = ds.getConnection();
            if (connection != null) {
                System.out.println("Connection successful!");
                connection.close();
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}

内容的提问来源于stack exchange,提问作者vinayak_narune

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.19 07:54:59