/** * DERBY-2026 make sure loginTimeout does not affect queries * * @throws SQLException */ public void clientTestDerby2026LoginTimeout() throws SQLException { String url = "jdbc:splice://" + TestConfiguration.getCurrent().getHostName() + ":" + TestConfiguration.getCurrent().getPort() + "/" + TestConfiguration.getCurrent().getDefaultDatabaseName(); try { DriverManager.setLoginTimeout(10); // System.out.println(url); try { Class.forName("org.apache.derby.jdbc.ClientDriver"); } catch (ClassNotFoundException e) { fail(e.getMessage()); } Connection conn = DriverManager.getConnection(url); TestRoutines.installRoutines(conn); CallableStatement cs = conn.prepareCall("CALL TESTROUTINE.SLEEP(20000)"); cs.execute(); // rollback to make sure our connection is ok. conn.rollback(); } finally { DriverManager.setLoginTimeout(0); } }
/** * s1:SEQNO, s2:KIND, s3:USERID Object[] params = new Object[]{name, subject, html, s1, s2, s3, * "", "", ""}; s1: 序号(1,1) s2: Y-发件人, R-接收人(Y,R) s3: 工号(08667616,08667616) 目前即使通过转码(GBK, EUC-KR, * ISO-2022-KR, KOI8-R, KOI8-U)也无法发送中文内容 * * @param name * @param subject * @param html * @param emps * @return * @throws Exception */ @SuppressWarnings("unchecked") public static Object[] send(String name, String subject, String html, String emps) throws Exception { String v = Setting.getValue(Setting.IDS_MAIL_SENDER); Map<String, Object> mailer = JSONUtil.getObject(v, Map.class); String username = (String) mailer.get("username"); String password = (String) mailer.get("password"); String driver = mailer.containsKey("driver") ? (String) mailer.get("driver") : null; String url = (String) mailer.get("url"); String sql = (String) mailer.get("sql"); int timeout = mailer.containsKey("timeout") ? (Integer) mailer.get("timeout") : 6; Object[] params = new Object[] {name, subject, html, "1,1", "Y,R", emps + "," + emps, "", "", ""}; int[] types = new int[] {Types.INTEGER, Types.VARCHAR, Types.VARCHAR}; Connection conn = null; Object[] r; try { if (driver != null) Class.forName(driver); DriverManager.setLoginTimeout(timeout); conn = DriverManager.getConnection(url, username, password); r = JDBCUtil.call(conn, sql, params, types); if (r != null && r.length > 2 && (Integer) r[0] != 0 && !"".equals(r[1])) System.out.println(r[1]); // throw new Exception((String) r[1]); } catch (Exception e1) { throw e1; } finally { if (conn != null) try { conn.close(); } catch (Exception e2) { } } return r; }
@Before public void setUp() throws Exception { DriverManager.setLoginTimeout(0); if (!System.getProperty("test.data.files", "").isEmpty()) { dataFileDir = System.getProperty("test.data.files"); } dataFileDir = dataFileDir.replace('\\', '/').replace("c:", ""); miniHS2 = new MiniHS2(conf); confOverlay = new HashMap<String, String>(); }
/** * * Test SSL client with non-SSL server fails * * @throws Exception */ @Test public void testInvalidConfig() throws Exception { clearSslConfOverlay(confOverlay); // Test in binary mode setBinaryConfOverlay(confOverlay); miniHS2.start(confOverlay); DriverManager.setLoginTimeout(4); try { hs2Conn = DriverManager.getConnection( miniHS2.getJdbcURL("default", SSL_CONN_PARAMS), System.getProperty("user.name"), "bar"); fail("SSL connection should fail with NON-SSL server"); } catch (SQLException e) { // expected error assertEquals("08S01", e.getSQLState().trim()); } System.setProperty(JAVA_TRUST_STORE_PROP, dataFileDir + File.separator + TRUST_STORE_NAME); System.setProperty(JAVA_TRUST_STORE_PASS_PROP, KEY_STORE_PASSWORD); try { hs2Conn = DriverManager.getConnection( miniHS2.getJdbcURL() + ";ssl=true", System.getProperty("user.name"), "bar"); fail("SSL connection should fail with NON-SSL server"); } catch (SQLException e) { // expected error assertEquals("08S01", e.getSQLState().trim()); } miniHS2.stop(); // Test in http mode with ssl properties specified in url System.clearProperty(JAVA_TRUST_STORE_PROP); System.clearProperty(JAVA_TRUST_STORE_PASS_PROP); setHttpConfOverlay(confOverlay); miniHS2.start(confOverlay); try { hs2Conn = DriverManager.getConnection( miniHS2.getJdbcURL("default", SSL_CONN_PARAMS), System.getProperty("user.name"), "bar"); fail("SSL connection should fail with NON-SSL server"); } catch (SQLException e) { // expected error assertEquals("08S01", e.getSQLState().trim()); } }
@Override public OracleDriver get() { // Speed up transfer rate System.setProperty("oracle.jdbc.TcpNoDelay", "true"); // Oracle Multi - Language System.setProperty("oracle.jdbc.defaultNChar", "true"); // try { final OracleDriver driver = new OracleDriver(); DriverManager.registerDriver(driver); DriverManager.setLoginTimeout(Database.CONNECTION_TIMEOUT); return driver; } catch (SQLException e) { throw new DBException("Failed registering oracle database driver", e); } }
public void create(DataSourceFactory dsf) throws Exception { FileInputStream fis = new FileInputStream(sqlScriptFile); DataInputStream dis = new DataInputStream(fis); byte[] buffer = new byte[(int) fis.getChannel().size()]; dis.readFully(buffer); String script = new String(buffer); Class.forName(jdbcDriver); String connectionString = dbSource.getPrefix() + ":"; if (dbSource.getHost() != null) { connectionString += "//" + dbSource.getHost(); if (dbSource.getPort() != -1) { connectionString += (":" + dbSource.getPort()); } connectionString += "/"; } connectionString += (dbSource.getDbName()); DriverManager.setLoginTimeout(2); Connection c = DriverManager.getConnection(connectionString, dbSource.getUser(), dbSource.getPassword()); Statement st = c.createStatement(); String[] statements = script.split("\\Q;\\E"); for (String statement : statements) { try { st.execute(statement); } catch (SQLException e) { System.err.println(statement); e.printStackTrace(); } } st.close(); c.close(); DBTableSourceDefinition def = new DBTableSourceDefinition(dbSource); dsf.getSourceManager().remove(name); dsf.getSourceManager().register(name, def); }
public String[] getAvailableTerminologies() throws UnexpectedError, ConnectionFailure { try { String[] terminologies = new String[] {}; ArrayList temp = new ArrayList(); DriverManager.setLoginTimeout(5); Connection sqlConnection; try { sqlConnection = new WrappedConnection(getUsername(), getPassword(), getDriver(), getServer()); } catch (ClassNotFoundException e1) { log.error("The class you specified for your sql driver could not be found on the path."); throw new ConnectionFailure( "The class you specified for your sql driver could not be found on the path."); } PreparedStatement getTerminologies = sqlConnection.prepareStatement("Select RSAB, SSN from MRSAB where SABIN = ?"); getTerminologies.setString(1, "Y"); ResultSet results = getTerminologies.executeQuery(); while (results.next()) { temp.add(results.getString("RSAB") + " -- " + results.getString("SSN")); } results.close(); getTerminologies.close(); sqlConnection.close(); terminologies = (String[]) temp.toArray(new String[temp.size()]); Arrays.sort(terminologies, new StringComparator()); return terminologies; } catch (ConnectionFailure e) { throw e; } catch (Exception e) { log.error("An error occurred while getting the terminologies.", e); throw new UnexpectedError("An error occurred while getting the terminologies.", e); } }
public void setLoginTimeout(final int i) { DriverManager.setLoginTimeout(i); }
@Override public void setLoginTimeout(int loginTimeout) throws SQLException { DriverManager.setLoginTimeout(loginTimeout); }