我尝试通过JDBC驱动程序从Google BigQuery查询数据,但是某些值似乎不正确。
步骤:
从https://storage.googleapis.com/simba-bq-release/jdbc/SimbaJDBCDriverforGoogleBigQuery42_1.2.2.1004.zip免费下载googlebigquery的Simba JDBC驱动程序
将驱动程序加载到Java App
通过jdbc连接google查询示例代码如下:
public static void main(String[] args) {
Connection conn = null;
String url ="jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;" +
"ProjectId=fedjdbc;OAuthType=0;DefaultDataset=jdbc;" +
"[email protected];" +
"OAuthPvtKeyPath=/Users/laptop/workspace/bigquery/accounts/fedjdbc-5cb29b8a02fb.json";
try {
Class.forName("com.simba.googlebigquery.jdbc42.Driver");
conn = DriverManager.getConnection(url);
query(conn);
conn.close();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
}
public static void query(Connection conn) {
String sql = "select * from numbers1";
sql = "select * from numbers1";
sql = "select timestamp(\"0001-01-01 00:00:00 UTC\") from jdbc.test_date";
try {
PreparedStatement stmt = conn.prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
System.out.println("query begin");
java.util.Date date = new java.util.Date();
System.out.println(System.currentTimeMillis());
ResultSet rs = stmt.executeQuery();
System.out.println(System.currentTimeMillis());
System.out.println("query end");
while (rs.next()) {
System.out.println(rs.getString(1));
//System.out.println(rs.getTimestamp(1));
}
rs.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
您会发现结果不是“ 0001-01-01 00:00:00.000000”,而是“ 0001-01-03 08:00:00.000000”。
你知道为什么吗?
时区在本地转换数据?
我在具有不同时区,相同问题的某些主机中对其进行了测试。