
net.snowflake.client.jdbcapi.ConnectionIT Maven / Gradle / Ivy
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package net.snowflake.client.jdbcapi;
import org.junit.Test;
import org.junit.Before;
import org.junit.After;
import static org.junit.Assert.*;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;
import com.snowflake.gscommon.core.SqlState;
/**
*
* @author hyu
*/
public class ConnectionIT extends BaseJDBCTest
{
@Before
public void setUp() throws Exception{
Connection con = getConnection();
Statement statement=con.createStatement();
statement.execute("create or replace database JDBC_DB1");
statement.execute("create or replace schema s1");
statement.close();
con.close();
}
@After
public void tearDown() throws Exception{
Connection con = getConnection();
Statement statement = con.createStatement();
statement.execute("drop database if exists JDBC_DB1");
statement.close();
con.close();
}
@Test
public void testSimpleConnection() throws SQLException{
Connection con = null;
con = getConnection();
Statement statement = con.createStatement();
ResultSet resultSet = statement.executeQuery("show parameters");
assertTrue(resultSet.next());
assertTrue(! con.isClosed());
statement.close();
con.close();
assertTrue(con.isClosed());
}
@Test
public void testConnectionGetAndSetDBAndSchema() throws SQLException{
Connection con = getConnection();
assertEquals("TESTSCHEMA", con.getSchema());
assertEquals("TESTDB", con.getCatalog());
con.setCatalog("JDBC_DB1");
assertEquals("JDBC_DB1", con.getCatalog());
assertEquals("PUBLIC", con.getSchema());
con.setSchema("S1");
assertEquals("S1", con.getSchema());
Statement statement = con.createStatement();
statement.execute("use database TESTDB");
statement.execute("use schema TESTSCHEMA");
assertEquals("TESTDB", con.getCatalog());
assertEquals("TESTSCHEMA", con.getSchema());
con.close();
}
@Test
public void testConnectionClientInfo() throws SQLException{
Connection con = getConnection();
Properties property = con.getClientInfo();
assertEquals(0, property.size());
Properties clientInfo = new Properties();
clientInfo.setProperty("name", "Peter");
clientInfo.setProperty("description", "SNOWFLAKE JDBC");
con.setClientInfo(clientInfo);
con.setClientInfo("clinetinfoA", "valueA");
Properties ci = con.getClientInfo();
assertEquals(3, ci.size());
String name = con.getClientInfo("name");
assertEquals("Peter", name);
con.close();
}
// not supported right now.
@Test
public void testReadOnlyConneciton() throws SQLException{
Connection con = getConnection();
assertTrue(!con.isReadOnly());
/*con.setReadOnly(true);
assertTrue(con.isReadOnly());
Statement statement = con.createStatement();
statement.execute("create or replace table TEST_JDBC_READ_ONLY(colA VARCHAR)");
statement.execute("drop table if exists TEST_JDBC_READ_ONLY");
statement.close();*/
con.close();
}
// only support get and set
@Test
public void testNetworkTimeout() throws SQLException{
Connection con = getConnection();
int millis = con.getNetworkTimeout();
assertEquals(0, millis);
con.setNetworkTimeout(null,200);
assertEquals(200, con.getNetworkTimeout());
//Statement statement = con.createStatement();
//statement.executeQuery("select count(*) from table(generator(rowCount => 1000000))");
con.close();
}
@Test
public void testAbort() throws SQLException{
Connection con = getConnection();
assertTrue(! con.isClosed());
con.abort(null);
assertTrue(con.isClosed());
}
@Test
public void testSetQueryTimeoutInConnectionStr() throws SQLException
{
Properties properties = new Properties();
properties.put("queryTimeout", "5");
Connection connection = getConnection(true, false, 0, properties);
Statement statement = connection.createStatement();
try {
statement.executeQuery("select count(*) from table(generator(timeLimit => 1000000))");
} catch (SQLException e)
{
assertTrue(true);
assertEquals(SqlState.QUERY_CANCELED, e.getSQLState());
assertEquals("SQL execution canceled", e.getMessage());
}
statement.close();
connection.close();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy