undefect. CWE-407 — 63 sites patched across 27 ecosystems

Authors: russell@unturf.com · brackishbert@gmail.com · foxhop.net · TimeHexOn.com

Patches, unit tests, benchmarks, whitepaper, and outreach briefs.
Public domain — no copyright claimed. Use freely.
This commit is contained in:
russell@unturf.com 2026-03-26 17:11:57 -04:00
commit 0a580b313d
70422 changed files with 17213626 additions and 0 deletions

View file

@ -0,0 +1,2 @@
modules = java.sql

View file

@ -0,0 +1,91 @@
/*
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package luckydogtennis;
import java.sql.Connection;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.DriverPropertyInfo;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
public class LuckyDogDriver implements Driver {
static {
registerDriver();
System.out.println("*****in static block LuckyDogDriver");
}
private static void registerDriver() {
try {
DriverManager.registerDriver(new LuckyDogDriver());
} catch (SQLException ex) {
Logger.getLogger(LuckyDogDriver.class.getName()).log(Level.SEVERE, null, ex);
}
}
public LuckyDogDriver() {
System.out.println("*****in LuckyDogDriver Constructor");
}
@Override
public Connection connect(String url, Properties info) throws SQLException {
if (acceptsURL(url)) {
return new StubConnection();
}
return null;
}
@Override
public boolean acceptsURL(String url) throws SQLException {
return url.matches("^jdbc:tennis:.*");
}
@Override
public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public int getMajorVersion() {
return 1;
}
@Override
public int getMinorVersion() {
return 0;
}
@Override
public boolean jdbcCompliant() {
return true;
}
@Override
public Logger getParentLogger() throws SQLFeatureNotSupportedException {
throw new UnsupportedOperationException("Not supported yet.");
}
}

View file

@ -0,0 +1,315 @@
/*
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package luckydogtennis;
import java.sql.Array;
import java.sql.Blob;
import java.sql.CallableStatement;
import java.sql.Clob;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.NClob;
import java.sql.PreparedStatement;
import java.sql.SQLClientInfoException;
import java.sql.SQLException;
import java.sql.SQLWarning;
import java.sql.SQLXML;
import java.sql.Savepoint;
import java.sql.Statement;
import java.sql.Struct;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.Executor;
public class StubConnection implements Connection{
@Override
public Statement createStatement() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public PreparedStatement prepareStatement(String sql) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public CallableStatement prepareCall(String sql) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public String nativeSQL(String sql) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setAutoCommit(boolean autoCommit) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public boolean getAutoCommit() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void commit() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void rollback() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void close() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public boolean isClosed() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public DatabaseMetaData getMetaData() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setReadOnly(boolean readOnly) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public boolean isReadOnly() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setCatalog(String catalog) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public String getCatalog() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setTransactionIsolation(int level) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public int getTransactionIsolation() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public SQLWarning getWarnings() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void clearWarnings() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Map<String, Class<?>> getTypeMap() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setTypeMap(Map<String, Class<?>> map) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setHoldability(int holdability) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public int getHoldability() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Savepoint setSavepoint() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Savepoint setSavepoint(String name) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void rollback(Savepoint savepoint) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void releaseSavepoint(Savepoint savepoint) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Clob createClob() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Blob createBlob() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public NClob createNClob() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public SQLXML createSQLXML() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public boolean isValid(int timeout) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setClientInfo(String name, String value) throws SQLClientInfoException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setClientInfo(Properties properties) throws SQLClientInfoException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public String getClientInfo(String name) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Properties getClientInfo() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Array createArrayOf(String typeName, Object[] elements) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Struct createStruct(String typeName, Object[] attributes) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setSchema(String schema) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public String getSchema() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void abort(Executor executor) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setNetworkTimeout(Executor executor, int milliseconds) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public int getNetworkTimeout() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public <T> T unwrap(Class<T> iface) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public boolean isWrapperFor(Class<?> iface) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
}

View file

@ -0,0 +1,27 @@
/*
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
module luckydogdriver {
requires transitive java.logging;
requires transitive java.sql;
exports luckydogtennis;
}

View file

@ -0,0 +1,315 @@
/*
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.luckydogtennis;
import java.sql.Array;
import java.sql.Blob;
import java.sql.CallableStatement;
import java.sql.Clob;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.NClob;
import java.sql.PreparedStatement;
import java.sql.SQLClientInfoException;
import java.sql.SQLException;
import java.sql.SQLWarning;
import java.sql.SQLXML;
import java.sql.Savepoint;
import java.sql.Statement;
import java.sql.Struct;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.Executor;
public class StubConnection implements Connection{
@Override
public Statement createStatement() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public PreparedStatement prepareStatement(String sql) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public CallableStatement prepareCall(String sql) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public String nativeSQL(String sql) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setAutoCommit(boolean autoCommit) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public boolean getAutoCommit() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void commit() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void rollback() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void close() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public boolean isClosed() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public DatabaseMetaData getMetaData() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setReadOnly(boolean readOnly) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public boolean isReadOnly() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setCatalog(String catalog) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public String getCatalog() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setTransactionIsolation(int level) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public int getTransactionIsolation() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public SQLWarning getWarnings() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void clearWarnings() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Map<String, Class<?>> getTypeMap() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setTypeMap(Map<String, Class<?>> map) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setHoldability(int holdability) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public int getHoldability() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Savepoint setSavepoint() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Savepoint setSavepoint(String name) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void rollback(Savepoint savepoint) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void releaseSavepoint(Savepoint savepoint) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Clob createClob() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Blob createBlob() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public NClob createNClob() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public SQLXML createSQLXML() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public boolean isValid(int timeout) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setClientInfo(String name, String value) throws SQLClientInfoException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setClientInfo(Properties properties) throws SQLClientInfoException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public String getClientInfo(String name) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Properties getClientInfo() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Array createArrayOf(String typeName, Object[] elements) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Struct createStruct(String typeName, Object[] attributes) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setSchema(String schema) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public String getSchema() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void abort(Executor executor) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setNetworkTimeout(Executor executor, int milliseconds) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public int getNetworkTimeout() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public <T> T unwrap(Class<T> iface) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public boolean isWrapperFor(Class<?> iface) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
}

View file

@ -0,0 +1,97 @@
/*
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.luckydogtennis;
import java.sql.Connection;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.DriverPropertyInfo;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
public class StubDriver implements Driver {
static {
System.out.println("*****in static block StubDriver");
registerDriver();
}
private static void registerDriver() {
try {
DriverManager.registerDriver(new StubDriver());
} catch (SQLException ex) {
Logger.getLogger(StubDriver.class.getName()).log(Level.SEVERE, null, ex);
}
}
public StubDriver() {
System.out.println("*****in StubDriver Constructor*************");
/*
for (StackTraceElement ste : Thread.currentThread().getStackTrace()) {
System.out.println(ste);
}
System.out.println("******************");
*/
}
@Override
public Connection connect(String url, Properties info) throws SQLException {
if (acceptsURL(url)) {
return new StubConnection();
}
return null;
}
@Override
public boolean acceptsURL(String url) throws SQLException {
return url.matches("^jdbc:stub:.*");
}
@Override
public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public int getMajorVersion() {
return 1;
}
@Override
public int getMinorVersion() {
return 0;
}
@Override
public boolean jdbcCompliant() {
return true;
}
@Override
public Logger getParentLogger() throws SQLFeatureNotSupportedException {
throw new UnsupportedOperationException("Not supported yet.");
}
}

View file

@ -0,0 +1,29 @@
/*
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
module mystubdriver {
requires transitive java.logging;
requires transitive java.sql;
exports com.luckydogtennis;
provides java.sql.Driver with
com.luckydogtennis.StubDriver;
}

View file

@ -0,0 +1,3 @@
# JDBC unit tests uses JUnit
JUnit.dirs= .
lib.dirs = /java/sql/util

View file

@ -0,0 +1,328 @@
/*
* Copyright (c) 2014, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package sql;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.ObjectInputStream;
import java.sql.BatchUpdateException;
import java.sql.SQLException;
import java.util.Arrays;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
import util.SerializedBatchUpdateException;
import util.BaseTest;
public class BatchUpdateExceptionTests extends BaseTest {
private final int[] uc = {1, 2, 3};
private final long[] luc = {1, 2, 3};
private final String testSrcDir = System.getProperty("test.src", ".")
+ File.separatorChar;
/**
* Create BatchUpdateException and setting all objects to null
*/
@Test
public void test() {
BatchUpdateException be = new BatchUpdateException(null,
null, errorCode, (int[]) null, null);
assertTrue(be.getMessage() == null && be.getSQLState() == null
&& be.getUpdateCounts() == null && be.getCause() == null
&& be.getLargeUpdateCounts() == null
&& be.getErrorCode() == errorCode);
}
/**
* Create BatchUpdateException with no-arg constructor
*/
@Test
public void test1() {
BatchUpdateException ex = new BatchUpdateException();
assertTrue(ex.getMessage() == null
&& ex.getSQLState() == null
&& ex.getCause() == null
&& ex.getErrorCode() == 0
&& ex.getUpdateCounts() == null
&& ex.getLargeUpdateCounts() == null);
}
/**
* Create BatchUpdateException with null Throwable
*/
@Test
public void test2() {
BatchUpdateException ex = new BatchUpdateException((Throwable) null);
assertTrue(ex.getMessage() == null
&& ex.getSQLState() == null
&& ex.getCause() == null
&& ex.getErrorCode() == 0
&& ex.getUpdateCounts() == null
&& ex.getLargeUpdateCounts() == null);
}
/**
* Create BatchUpdateException with message and update counts
*/
@Test
public void test3() {
BatchUpdateException ex = new BatchUpdateException(reason, uc);
assertTrue(ex.getMessage().equals(reason)
&& ex.getSQLState() == null
&& ex.getCause() == null
&& ex.getErrorCode() == 0
&& Arrays.equals(ex.getUpdateCounts(), uc)
&& Arrays.equals(ex.getLargeUpdateCounts(), luc)
);
}
/**
* Create BatchUpdateException with update counts
*/
@Test
public void test4() {
BatchUpdateException ex = new BatchUpdateException(uc);
assertTrue(ex.getMessage() == null
&& ex.getSQLState() == null
&& ex.getCause() == null
&& ex.getErrorCode() == 0
&& Arrays.equals(ex.getUpdateCounts(), uc)
&& Arrays.equals(ex.getLargeUpdateCounts(), luc)
);
}
/**
* Create BatchUpdateException with Throwable and update counts
*/
@Test
public void test5() {
BatchUpdateException ex = new BatchUpdateException(uc, t);
assertTrue(ex.getMessage().equals(cause)
&& ex.getSQLState() == null
&& cause.equals(ex.getCause().toString())
&& ex.getErrorCode() == 0
&& Arrays.equals(ex.getUpdateCounts(), uc)
&& Arrays.equals(ex.getLargeUpdateCounts(), luc)
);
}
/**
* Create BatchUpdateException with message, Throwable, and update counts
*/
@Test
public void test6() {
BatchUpdateException ex = new BatchUpdateException(reason, uc, t);
assertTrue(ex.getMessage().equals(reason)
&& ex.getSQLState() == null
&& cause.equals(ex.getCause().toString())
&& ex.getErrorCode() == 0
&& Arrays.equals(ex.getUpdateCounts(), uc)
&& Arrays.equals(ex.getLargeUpdateCounts(), luc)
);
}
/**
* Create BatchUpdateException with message, SQLState, Throwable, and update
* counts
*/
@Test
public void test7() {
BatchUpdateException ex = new BatchUpdateException(reason, state, uc, t);
assertTrue(ex.getMessage().equals(reason)
&& ex.getSQLState().equals(state)
&& cause.equals(ex.getCause().toString())
&& ex.getErrorCode() == 0
&& Arrays.equals(ex.getUpdateCounts(), uc)
&& Arrays.equals(ex.getLargeUpdateCounts(), luc)
);
}
/**
* Create BatchUpdateException with message, SQLState, errorCode code
* Throwable, and update counts
*/
@Test
public void test8() {
BatchUpdateException ex = new BatchUpdateException(reason, state, errorCode,
uc, t);
assertTrue(ex.getMessage().equals(reason)
&& ex.getSQLState().equals(state)
&& cause.equals(ex.getCause().toString())
&& ex.getErrorCode() == errorCode
&& Arrays.equals(ex.getUpdateCounts(), uc)
&& Arrays.equals(ex.getLargeUpdateCounts(), luc)
);
}
/**
* Create BatchUpdateException with message, SQLState, errorCode code
* Throwable, and long [] update counts
*/
@Test
public void test9() {
BatchUpdateException ex = new BatchUpdateException(reason, state, errorCode,
luc, t);
assertTrue(ex.getMessage().equals(reason)
&& ex.getSQLState().equals(state)
&& cause.equals(ex.getCause().toString())
&& ex.getErrorCode() == errorCode
&& Arrays.equals(ex.getUpdateCounts(), uc)
&& Arrays.equals(ex.getLargeUpdateCounts(), luc)
);
}
/**
* Validate that a copy of the update counts array is made
*/
@Test
public void test10() {
int[] uc1 = {1, 2};
BatchUpdateException ex = new BatchUpdateException(uc1);
assertTrue(Arrays.equals(ex.getUpdateCounts(), uc1));
uc1[0] = 6689;
assertFalse(Arrays.equals(ex.getUpdateCounts(), uc1));
}
/**
* Validate that if null is specified for the update count, it is returned
* as null
*/
@Test
public void test11() {
BatchUpdateException ex = new BatchUpdateException((int[]) null);
assertTrue(ex.getMessage() == null && ex.getSQLState() == null
&& ex.getErrorCode() == 0 && ex.getUpdateCounts() == null
&& ex.getLargeUpdateCounts() == null);
}
/**
* Serialize a BatchUpdateException and make sure you can read it back
* properly
*/
@Test
public void test12() throws Exception {
BatchUpdateException be = new BatchUpdateException(reason, state, errorCode,
uc, t);
BatchUpdateException bue
= createSerializedException(be);
assertTrue(reason.equals(bue.getMessage())
&& bue.getSQLState().equals(state)
&& cause.equals(bue.getCause().toString())
&& bue.getErrorCode() == errorCode
&& Arrays.equals(bue.getLargeUpdateCounts(), luc)
&& Arrays.equals(bue.getUpdateCounts(), uc));
}
/**
* De-Serialize a BatchUpdateException from JDBC 4.0 and make sure you can
* read it back properly
*/
@Test
public void test13() throws Exception {
String reason1 = "This was the error msg";
String state1 = "user defined sqlState";
String cause1 = "java.lang.Throwable: throw 1";
int errorCode1 = 99999;
Throwable t = new Throwable("throw 1");
int[] uc1 = {1, 2, 21};
long[] luc1 = {1, 2, 21};
ObjectInputStream ois = new ObjectInputStream(
new ByteArrayInputStream(SerializedBatchUpdateException.DATA));
BatchUpdateException bue = (BatchUpdateException) ois.readObject();
assertTrue(reason1.equals(bue.getMessage())
&& bue.getSQLState().equals(state1)
&& bue.getErrorCode() == errorCode1
&& cause1.equals(bue.getCause().toString())
&& Arrays.equals(bue.getLargeUpdateCounts(), luc1)
&& Arrays.equals(bue.getUpdateCounts(), uc1));
}
/**
* Serialize a BatchUpdateException with an Integer.MAX_VALUE + 1 and
* validate you can read it back properly
*/
@Test
public void test14() throws Exception {
int[] uc1 = {Integer.MAX_VALUE, Integer.MAX_VALUE + 1};
long[] luc1 = {Integer.MAX_VALUE, Integer.MAX_VALUE + 1};
BatchUpdateException be = new BatchUpdateException(reason, state, errorCode,
luc1, t);
BatchUpdateException bue
= createSerializedException(be);
assertTrue(reason.equals(bue.getMessage())
&& bue.getSQLState().equals(state)
&& cause.equals(bue.getCause().toString())
&& bue.getErrorCode() == errorCode
&& Arrays.equals(bue.getLargeUpdateCounts(), luc1)
&& Arrays.equals(bue.getUpdateCounts(), uc1));
}
/**
* Validate that the ordering of the returned Exceptions is correct
* using for-each loop
*/
@Test
public void test15() {
BatchUpdateException ex = new BatchUpdateException("Exception 1", uc, t1);
BatchUpdateException ex1 = new BatchUpdateException("Exception 2", uc);
BatchUpdateException ex2 = new BatchUpdateException("Exception 3", uc, t2);
ex.setNextException(ex1);
ex.setNextException(ex2);
int num = 0;
for (Throwable e : ex) {
assertTrue(msgs[num++].equals(e.getMessage()));
}
}
/**
* Validate that the ordering of the returned Exceptions is correct
* using traditional while loop
*/
@Test
public void test16() {
BatchUpdateException ex = new BatchUpdateException("Exception 1", uc, t1);
BatchUpdateException ex1 = new BatchUpdateException("Exception 2", uc);
BatchUpdateException ex2 = new BatchUpdateException("Exception 3", uc, t2);
ex.setNextException(ex1);
ex.setNextException(ex2);
SQLException sqe = ex;
int num = 0;
while (sqe != null) {
assertTrue(msgs[num++].equals(sqe.getMessage()));
Throwable c = sqe.getCause();
while (c != null) {
assertTrue(msgs[num++].equals(c.getMessage()));
c = c.getCause();
}
sqe = sqe.getNextException();
}
}
}

View file

@ -0,0 +1,138 @@
/*
* Copyright (c) 2015, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package sql;
import org.junit.jupiter.params.provider.ValueSource;
import util.BaseTest;
import util.StubConnection;
import java.sql.CallableStatement;
import java.sql.SQLException;
import org.junit.jupiter.api.AfterEach;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
public class CallableStatementTests extends BaseTest {
private CallableStatement cstmt;
@BeforeEach
public void setUpMethod() throws Exception {
cstmt = new StubConnection().prepareCall("{call SuperHero_Proc(?)}");
}
@AfterEach
public void tearDownMethod() throws Exception {
cstmt.close();
}
/*
* Verify that enquoteLiteral creates a valid literal and converts every
* single quote to two single quotes
*/
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("validEnquotedLiteralValues")
public void test00(String s, String expected) throws SQLException {
assertEquals(expected, cstmt.enquoteLiteral(s));
}
/*
* Validate a NullPointerException is thrown if the string passed to
* enquoteLiteral is null
*/
@Test
public void test01() throws SQLException {
assertThrows(NullPointerException.class, () -> cstmt.enquoteLiteral(null));
}
/*
* Validate that enquoteIdentifier returns the expected value
*/
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("validEnquotedIdentifierValues")
public void test02(String s, boolean alwaysQuote, String expected) throws SQLException {
assertEquals(expected, cstmt.enquoteIdentifier(s, alwaysQuote));
}
/*
* Validate that a SQLException is thrown for values that are not valid
* for a SQL identifier
*/
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("invalidEnquotedIdentifierValues")
public void test03(String s, boolean alwaysQuote) throws SQLException {
assertThrows(SQLException.class, () -> cstmt.enquoteIdentifier(s, alwaysQuote));
}
/*
* Validate a NullPointerException is thrown is the string passed to
* enquoteIdentiifer is null
*/
@ParameterizedTest(autoCloseArguments = false)
@ValueSource(booleans = {true, false})
public void test04(boolean alwaysQuote) throws SQLException {
assertThrows(NullPointerException.class, () -> cstmt.enquoteIdentifier(null, alwaysQuote));
}
/*
* Validate that isSimpleIdentifier returns the expected value
*/
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("simpleIdentifierValues")
public void test05(String s, boolean expected) throws SQLException {
assertEquals(expected, cstmt.isSimpleIdentifier(s));
}
/*
* Validate a NullPointerException is thrown if the string passed to
* isSimpleIdentifier is null
*/
@Test
public void test06() throws SQLException {
assertThrows(NullPointerException.class, () -> cstmt.isSimpleIdentifier(null));
}
/*
* Verify that enquoteLiteral creates a valid literal and converts every
* single quote to two single quotes
*/
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("validEnquotedNCharLiteralValues")
public void test07(String s, String expected) throws SQLException {
assertEquals(expected, cstmt.enquoteNCharLiteral(s));
}
/*
* Validate a NullPointerException is thrown if the string passed to
* enquoteNCharLiteral is null
*/
@Test
public void test08() throws SQLException {
assertThrows(NullPointerException.class, () -> cstmt.enquoteNCharLiteral(null));
}
}

View file

@ -0,0 +1,130 @@
/*
* Copyright (c) 2025, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package sql;
import org.junit.jupiter.params.provider.ValueSource;
import util.BaseTest;
import util.StubConnection;
import java.sql.SQLException;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
public class ConnectionTests extends BaseTest {
protected StubConnection conn;
@BeforeEach
public void setUpMethod() throws Exception {
conn = new StubConnection();
}
/*
* Verify that enquoteLiteral creates a valid literal and converts every
* single quote to two single quotes
*/
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("validEnquotedLiteralValues")
public void test00(String s, String expected) throws SQLException {
assertEquals(expected, conn.enquoteLiteral(s));
}
/*
* Validate a NullPointerException is thrown if the string passed to
* enquoteLiteral is null
*/
@Test
public void test01() throws SQLException {
assertThrows(NullPointerException.class, () -> conn.enquoteLiteral(null));
}
/*
* Validate that enquoteIdentifier returns the expected value
*/
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("validEnquotedIdentifierValues")
public void test02(String s, boolean alwaysQuote, String expected) throws SQLException {
assertEquals(expected, conn.enquoteIdentifier(s, alwaysQuote));
}
/*
* Validate that a SQLException is thrown for values that are not valid
* for a SQL identifier
*/
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("invalidEnquotedIdentifierValues")
public void test03(String s, boolean alwaysQuote) throws SQLException {
assertThrows(SQLException.class, () -> conn.enquoteIdentifier(s, alwaysQuote));
}
/*
* Validate a NullPointerException is thrown is the string passed to
* enquoteIdentiifer is null
*/
@ParameterizedTest(autoCloseArguments = false)
@ValueSource(booleans = {true, false})
public void test04(boolean alwaysQuote) throws SQLException {
assertThrows(NullPointerException.class, () -> conn.enquoteIdentifier(null, alwaysQuote));
}
/*
* Validate that isSimpleIdentifier returns the expected value
*/
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("simpleIdentifierValues")
public void test05(String s, boolean expected) throws SQLException {
assertEquals(expected, conn.isSimpleIdentifier(s));
}
/*
* Validate a NullPointerException is thrown if the string passed to
* isSimpleIdentifier is null
*/
@Test
public void test06() throws SQLException {
assertThrows(NullPointerException.class, () -> conn.isSimpleIdentifier(null));
}
/*
* Verify that enquoteLiteral creates a valid literal and converts every
* single quote to two single quotes
*/
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("validEnquotedNCharLiteralValues")
public void test07(String s, String expected) throws SQLException {
assertEquals(expected, conn.enquoteNCharLiteral(s));
}
/*
* Validate a NullPointerException is thrown if the string passed to
* enquoteNCharLiteral is null
*/
@Test
public void test08() throws SQLException {
assertThrows(NullPointerException.class, () -> conn.enquoteNCharLiteral(null));
}
}

View file

@ -0,0 +1,211 @@
/*
* Copyright (c) 2014, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package sql;
import java.sql.DataTruncation;
import java.sql.SQLException;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
import util.BaseTest;
public class DataTruncationTests extends BaseTest {
private final String READ_TRUNCATION = "01004";
private final String WRITE_TRUNCATION = "22001";
private final String dtReason = "Data truncation";
private final int dterrorCode = 0;
private final String[] dtmsgs = {dtReason, "cause 1", dtReason,
dtReason, "cause 2"};
private boolean onRead = false;
private final boolean parameter = false;
private final int index = 21;
private final int dataSize = 25;
private final int transferSize = 10;
/**
* Create DataTruncation object indicating a truncation on read
*/
@Test
public void test() {
onRead = true;
DataTruncation e = new DataTruncation(index, parameter, onRead,
dataSize, transferSize);
assertTrue(e.getMessage().equals(dtReason)
&& e.getSQLState().equals(READ_TRUNCATION)
&& e.getCause() == null
&& e.getErrorCode() == dterrorCode
&& e.getParameter() == parameter
&& e.getRead() == onRead
&& e.getDataSize() == dataSize
&& e.getTransferSize() == transferSize
&& e.getIndex() == index);
}
/**
* Create DataTruncation object indicating a truncation on write
*/
@Test
public void test1() {
onRead = false;
DataTruncation e = new DataTruncation(index, parameter, onRead,
dataSize, transferSize);
assertTrue(e.getMessage().equals(dtReason)
&& e.getSQLState().equals(WRITE_TRUNCATION)
&& e.getCause() == null
&& e.getErrorCode() == dterrorCode
&& e.getParameter() == parameter
&& e.getRead() == onRead
&& e.getDataSize() == dataSize
&& e.getTransferSize() == transferSize
&& e.getIndex() == index);
}
/**
* Create DataTruncation object indicating a truncation on read with a
* Throwable
*/
@Test
public void test2() {
onRead = true;
DataTruncation e = new DataTruncation(index, parameter, onRead,
dataSize, transferSize, t);
assertTrue(e.getMessage().equals(dtReason)
&& e.getSQLState().equals(READ_TRUNCATION)
&& cause.equals(e.getCause().toString())
&& e.getErrorCode() == dterrorCode
&& e.getParameter() == parameter
&& e.getRead() == onRead
&& e.getDataSize() == dataSize
&& e.getTransferSize() == transferSize
&& e.getIndex() == index);
}
/**
* Create DataTruncation object indicating a truncation on read with null
* specified for the Throwable
*/
@Test
public void test3() {
onRead = true;;
DataTruncation e = new DataTruncation(index, parameter, onRead,
dataSize, transferSize, null);
assertTrue(e.getMessage().equals(dtReason)
&& e.getSQLState().equals(READ_TRUNCATION)
&& e.getCause() == null
&& e.getErrorCode() == dterrorCode
&& e.getParameter() == parameter
&& e.getRead() == onRead
&& e.getDataSize() == dataSize
&& e.getTransferSize() == transferSize
&& e.getIndex() == index);
}
/**
* Create DataTruncation object indicating a truncation on read and you can
* pass a -1 for the index
*/
@Test
public void test4() {
onRead = true;
int negIndex = -1;
DataTruncation e = new DataTruncation(negIndex, parameter, onRead,
dataSize, transferSize);
assertTrue(e.getMessage().equals(dtReason)
&& e.getSQLState().equals(READ_TRUNCATION)
&& e.getCause() == null
&& e.getErrorCode() == dterrorCode
&& e.getParameter() == parameter
&& e.getRead() == onRead
&& e.getDataSize() == dataSize
&& e.getTransferSize() == transferSize
&& e.getIndex() == negIndex);
}
/**
* Serialize a DataTruncation and make sure you can read it back properly
*/
@Test
public void test5() throws Exception {
DataTruncation e = new DataTruncation(index, parameter, onRead,
dataSize, transferSize);
DataTruncation ex1 = createSerializedException(e);
assertTrue(e.getMessage().equals(dtReason)
&& e.getSQLState().equals(READ_TRUNCATION)
&& e.getCause() == null
&& e.getErrorCode() == dterrorCode
&& e.getParameter() == parameter
&& e.getRead() == onRead
&& e.getDataSize() == dataSize
&& e.getTransferSize() == transferSize
&& e.getIndex() == index);
}
/**
* Validate that the ordering of the returned Exceptions is correct using
* for-each loop
*/
@Test
public void test11() {
DataTruncation ex = new DataTruncation(index, parameter, onRead,
dataSize, transferSize, t1);
DataTruncation ex1 = new DataTruncation(index, parameter, onRead,
dataSize, transferSize);
DataTruncation ex2 = new DataTruncation(index, parameter, onRead,
dataSize, transferSize, t2);
ex.setNextException(ex1);
ex.setNextException(ex2);
int num = 0;
for (Throwable e : ex) {
assertTrue(dtmsgs[num++].equals(e.getMessage()));
}
}
/**
* Validate that the ordering of the returned Exceptions is correct using
* traditional while loop
*/
@Test
public void test12() {
DataTruncation ex = new DataTruncation(index, parameter, onRead,
dataSize, transferSize, t1);
DataTruncation ex1 = new DataTruncation(index, parameter, onRead,
dataSize, transferSize);
DataTruncation ex2 = new DataTruncation(index, parameter, onRead,
dataSize, transferSize, t2);
ex.setNextException(ex1);
ex.setNextException(ex2);
int num = 0;
SQLException sqe = ex;
while (sqe != null) {
assertTrue(dtmsgs[num++].equals(sqe.getMessage()));
Throwable c = sqe.getCause();
while (c != null) {
assertTrue(dtmsgs[num++].equals(c.getMessage()));
c = c.getCause();
}
sqe = sqe.getNextException();
}
}
}

View file

@ -0,0 +1,375 @@
/*
* Copyright (c) 2014, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package sql;
import java.sql.Date;
import java.time.LocalDate;
import java.util.stream.Stream;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import util.BaseTest;
public class DateTests extends BaseTest {
/*
* Validate an IllegalArgumentException is thrown for an invalid Date string
*/
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("invalidDateValues")
public void test(String d) throws Exception {
assertThrows(IllegalArgumentException.class, () -> Date.valueOf(d));
}
/*
* Test that a date created from a date string is equal to the value
* returned from toString()
*/
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("validDateValues")
public void test00(String d, String expectedD) {
Date d1 = Date.valueOf(d);
Date d2 = Date.valueOf(expectedD);
assertTrue(d1.equals(d2) && d2.equals(d1)
&& d1.toString().equals(expectedD), "Error d1 != d2");
}
/*
* Validate that a Date.after() returns false when same date is compared
*/
@Test
public void test01() {
Date d = Date.valueOf("1961-08-30");
assertFalse(d.after(d), "Error d.after(d) = true");
}
/*
* Validate that a Date.after() returns true when later date is compared to
* earlier date
*/
@Test
public void test2() {
Date d = Date.valueOf("1961-08-30");
Date d2 = new Date(System.currentTimeMillis());
assertTrue(d2.after(d), "Error d2.after(d) = false");
}
/*
* Validate that a Date.after() returns false when earlier date is compared
* to later date
*/
@Test
public void test3() {
Date d = Date.valueOf("1961-08-30");
Date d2 = new Date(d.getTime());
assertFalse(d.after(d2), "Error d.after(d2) = true");
}
/*
* Validate that a Date.after() returns false when date compared to another
* date created from the original date
*/
@Test
public void test4() {
Date d = Date.valueOf("1961-08-30");
Date d2 = new Date(d.getTime());
assertFalse(d.after(d2), "Error d.after(d2) = true");
assertFalse(d2.after(d), "Error d2.after(d) = true");
}
/*
* Validate that a Date.before() returns false when same date is compared
*/
@Test
public void test5() {
Date d = Date.valueOf("1961-08-30");
assertFalse(d.before(d), "Error d.before(d) = true");
}
/*
* Validate that a Date.before() returns true when earlier date is compared
* to later date
*/
@Test
public void test6() {
Date d = Date.valueOf("1961-08-30");
Date d2 = new Date(System.currentTimeMillis());
assertTrue(d.before(d2), "Error d.before(d2) = false");
}
/*
* Validate that a Date.before() returns false when later date is compared
* to earlier date
*/
@Test
public void test7() {
Date d = Date.valueOf("1961-08-30");
Date d2 = new Date(d.getTime());
assertFalse(d2.before(d), "Error d2.before(d) = true");
}
/*
* Validate that a Date.before() returns false when date compared to another
* date created from the original date
*/
@Test
public void test8() {
Date d = Date.valueOf("1961-08-30");
Date d2 = new Date(d.getTime());
assertFalse(d.before(d2), "Error d.before(d2) = true");
assertFalse(d2.before(d), "Error d2.before(d) = true");
}
/*
* Validate that a Date.compareTo returns 0 when both Date objects are the
* same
*/
@Test
public void test9() {
Date d = Date.valueOf("1961-08-30");
assertTrue(d.compareTo(d) == 0, "Error d.compareTo(d) !=0");
}
/*
* Validate that a Date.compareTo returns 0 when both Date objects represent
* the same date
*/
@Test
public void test10() {
Date d = Date.valueOf("1961-08-30");
Date d2 = new Date(d.getTime());
assertTrue(d.compareTo(d2) == 0, "Error d.compareTo(d2) !=0");
}
/*
* Validate that a Date.compareTo returns -1 when comparing a date to a
* later date
*/
@Test
public void test11() {
Date d = Date.valueOf("1961-08-30");
Date d2 = new Date(System.currentTimeMillis());
assertTrue(d.compareTo(d2) == -1, "Error d.compareTo(d2) != -1");
}
/*
* Validate that a Date.compareTo returns 1 when comparing a date to an
* earlier date
*/
@Test
public void test12() {
Date d = Date.valueOf("1961-08-30");
Date d2 = new Date(System.currentTimeMillis());
assertTrue(d2.compareTo(d) == 1, "Error d.compareTo(d2) != 1");
}
/*
* Validate that a Date made from a LocalDate are equal
*/
@Test
public void test13() {
Date d = Date.valueOf("1961-08-30");
LocalDate ldt = d.toLocalDate();
Date d2 = Date.valueOf(ldt);
assertTrue(d.equals(d2), "Error d != d2");
}
/*
* Validate that a Date LocalDate value, made from a LocalDate are equal
*/
@Test
public void test14() {
LocalDate ldt = LocalDate.now();
Date d = Date.valueOf(ldt);
assertTrue(ldt.equals(d.toLocalDate()),
"Error LocalDate values are not equal");
}
/*
* Validate an NPE occurs when a null LocalDate is passed to valueOf
*/
@Test
public void test15() throws Exception {
LocalDate ld = null;
assertThrows(NullPointerException.class, () -> Date.valueOf(ld));
}
/*
* Validate an UnsupportedOperationException occurs when toInstant() is
* called
*/
@Test
public void test16() throws Exception {
Date d = Date.valueOf("1961-08-30");
assertThrows(UnsupportedOperationException.class, d::toInstant);
}
/*
* Validate that two Date objects are equal when one is created from the
* toString() of the other
*/
@Test
public void test17() {
Date d = Date.valueOf("1961-08-30");
Date d2 = Date.valueOf(d.toString());
assertTrue(d.equals(d2) && d2.equals(d), "Error d != d2");
}
/*
* Validate that two Date values one created using valueOf and another via a
* constructor are equal
*/
@Test
public void test18() {
Date d = Date.valueOf("1961-08-30");
Date d2 = new Date(61, 7, 30);
assertTrue(d.equals(d2), "Error d != d2");
}
/*
* Validate that two Date values one created using getTime() of the other
* are equal
*/
@Test
public void test19() {
Date d = Date.valueOf("1961-08-30");
Date d2 = new Date(d.getTime());
assertTrue(d.equals(d2), "Error d != d2");
}
/*
* Validate that a Date value is equal to itself
*/
@Test
public void test20() {
Date d = Date.valueOf("1961-08-30");
assertTrue(d.equals(d), "Error d != d");
}
/*
* Validate an IllegalArgumentException is thrown for calling getHours
*/
@Test
public void test21() throws Exception {
Date d = Date.valueOf("1961-08-30");
assertThrows(IllegalArgumentException.class, d::getHours);
}
/*
* Validate an IllegalArgumentException is thrown for calling getMinutes
*/
@Test
public void test22() throws Exception {
Date d = Date.valueOf("1961-08-30");
assertThrows(IllegalArgumentException.class, d::getMinutes);
}
/*
* Validate an IllegalArgumentException is thrown for calling getSeconds
*/
@Test
public void test23() throws Exception {
Date d = Date.valueOf("1961-08-30");
assertThrows(IllegalArgumentException.class, d::getSeconds);
}
/*
* Validate an IllegalArgumentException is thrown for calling setHours
*/
@Test
public void test24() throws Exception {
Date d = Date.valueOf("1961-08-30");
assertThrows(IllegalArgumentException.class, () -> d.setHours(8));
}
/*
* Validate an IllegalArgumentException is thrown for calling setMinutes
*/
@Test
public void test25() throws Exception {
Date d = Date.valueOf("1961-08-30");
assertThrows(IllegalArgumentException.class, () -> d.setMinutes(0));
}
/*
* Validate an IllegalArgumentException is thrown for calling setSeconds
*/
@Test
public void test26() throws Exception {
Date d = Date.valueOf("1961-08-30");
assertThrows(IllegalArgumentException.class, () -> d.setSeconds(0));
}
/*
* DataProvider used to provide Date which are not valid and are used
* to validate that an IllegalArgumentException will be thrown from the
* valueOf method
*/
private Stream<String> invalidDateValues() {
return Stream.of(
"20009-11-01",
"09-11-01",
"-11-01",
"2009-111-01",
"2009--01",
"2009-13-01",
"2009-11-011",
"2009-11-",
"2009-11-00",
"2009-11-33",
"--",
"",
null,
"-",
"2009",
"2009-01",
"---",
"2009-13--1",
"1900-1-0",
"2009-01-01 10:50:01",
"1996-12-10 12:26:19.1",
"10:50:01"
);
}
/*
* DataProvider used to provide Dates which are valid and are used
* to validate that an IllegalArgumentException will not be thrown from the
* valueOf method and the corect value from toString() is returned
*/
private Stream<Arguments> validDateValues() {
return Stream.of(
Arguments.of("2009-08-30", "2009-08-30"),
Arguments.of("2009-01-8", "2009-01-08"),
Arguments.of("2009-1-01", "2009-01-01"),
Arguments.of("2009-1-1", "2009-01-01")
);
}
}

View file

@ -0,0 +1,366 @@
/*
* Copyright (c) 2014, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package sql;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.CharArrayReader;
import java.io.CharArrayWriter;
import java.io.File;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Collection;
import java.util.Collections;
import java.util.Properties;
import java.util.stream.Collectors;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import util.StubDriver;
public class DriverManagerTests {
private final String StubDriverURL = "jdbc:tennis:boy";
private final String StubDriverDAURL = "jdbc:luckydog:tennis";
private final String InvalidURL = "jdbc:cardio:tennis";
private String[] results = {"output", "more output", "and more", "the end"};
private String noOutput = "should not find this";
public DriverManagerTests() {
}
@BeforeEach
public void setUpMethod() throws Exception {
removeAllDrivers();
}
/**
* Utility method to remove all registered drivers
*/
private static void removeAllDrivers() {
java.util.Enumeration e = DriverManager.getDrivers();
while (e.hasMoreElements()) {
try {
DriverManager.deregisterDriver((Driver) (e.nextElement()));
} catch (SQLException ex) {
System.out.print(ex.getMessage());
}
}
}
/**
* Utility method to see if a driver is registered
*/
private boolean isDriverRegistered(Driver d) {
boolean foundDriver = false;
java.util.Enumeration e = DriverManager.getDrivers();
while (e.hasMoreElements()) {
if (d == (Driver) e.nextElement()) {
foundDriver = true;
break;
}
}
return foundDriver;
}
/**
* Validate that values set using setLoginTimeout will be returned by
* getLoginTimeout
*/
@Test
public void test() {
int[] vals = {-1, 0, 5};
for (int val : vals) {
DriverManager.setLoginTimeout(val);
assertEquals(DriverManager.getLoginTimeout(), val);
}
}
/**
* Validate that NullPointerException is thrown when null is passed to
* registerDriver
*/
@Test
public void test1() throws Exception {
Driver d = null;
assertThrows(NullPointerException.class,
() -> DriverManager.registerDriver(d));
}
/**
* Validate that NullPointerException is thrown when null is passed to
* registerDriver
*/
@Test
public void test2() throws Exception {
Driver d = null;
assertThrows(NullPointerException.class, () ->
DriverManager.registerDriver(d, null));
}
/**
* Validate that a null value allows for deRegisterDriver to return
*/
@Test
public void test3() throws Exception {
DriverManager.deregisterDriver(null);
}
/**
* Validate that SQLException is thrown when there is no Driver to service
* the URL
*/
@Test
public void test4() throws Exception {
assertThrows(SQLException.class, () -> DriverManager.getConnection(InvalidURL));
}
/**
* Validate that SQLException is thrown when there is no Driver to service
* the URL
*/
@Test
public void test5() throws Exception {
assertThrows(SQLException.class, () -> DriverManager.getConnection(InvalidURL, new Properties()));
}
/**
* Validate that SQLException is thrown when there is no Driver to service
* the URL
*/
@Test
public void test6() throws Exception {
assertThrows(SQLException.class, () -> DriverManager.getConnection(InvalidURL, "LuckyDog", "tennisanyone"));
}
/**
* Validate that SQLException is thrown when null is passed for the URL
*/
@Test
public void test7() throws Exception {
assertThrows(SQLException.class, () -> DriverManager.getConnection(null));
}
/**
* Validate that SQLException is thrown when null is passed for the URL
*/
@Test
public void test8() throws Exception {
assertThrows(SQLException.class, () -> DriverManager.getConnection(null, new Properties()));
}
/**
* Validate that SQLException is thrown when null is passed for the URL
*/
@Test
public void test9() throws Exception {
assertThrows(SQLException.class, () -> DriverManager.getConnection(null, "LuckyDog", "tennisanyone"));
}
/**
* Validate that SQLException is thrown when there is no Driver to service
* the URL
*/
@Test
public void test10() throws Exception {
assertThrows(SQLException.class, () -> DriverManager.getDriver(InvalidURL));
}
/**
* Validate that SQLException is thrown when null is passed for the URL
*/
@Test
public void test11() throws Exception {
assertThrows(SQLException.class, () -> DriverManager.getDriver(null));
}
/**
* Validate that a non-null Driver is returned by getDriver when a valid URL
* is specified
*/
@Test
public void test12() throws Exception {
DriverManager.registerDriver(new StubDriver());
assertTrue(DriverManager.getDriver(StubDriverURL) != null);
}
/**
* Validate that SQLException is thrown when the URL is not valid for any of
* the registered drivers
*/
@Test
public void test13() throws Exception {
DriverManager.registerDriver(new StubDriver());
assertThrows(SQLException.class, () -> DriverManager.getDriver(InvalidURL));
}
/**
* Validate that a Connection object is returned when a valid URL is
* specified to getConnection
*
*/
@Test
public void test14() throws Exception {
DriverManager.registerDriver(new StubDriver());
assertTrue(
DriverManager.getConnection(StubDriverURL) != null);
assertTrue(DriverManager.getConnection(StubDriverURL,
"LuckyDog", "tennisanyone") != null);
Properties props = new Properties();
props.put("user", "LuckyDog");
props.put("password", "tennisanyone");
assertTrue(
DriverManager.getConnection(StubDriverURL,
props) != null);
}
/**
* Register a driver and make sure you find it via its URL. Deregister the
* driver and validate it is not longer registered
*
* @throws Exception
*/
@Test()
public void test15() throws Exception {
DriverManager.registerDriver(new StubDriver());
Driver d = DriverManager.getDriver(StubDriverURL);
assertTrue(d != null);
assertTrue(isDriverRegistered(d));
DriverManager.deregisterDriver(d);
assertFalse(isDriverRegistered(d));
}
/**
* Validate that DriverAction.release is called when a driver is registered
* via registerDriver(Driver, DriverAction)
*
* @throws Exception
*/
@Test
public void test16() throws Exception {
File file = new File(util.StubDriverDA.DriverActionCalled);
file.delete();
assertFalse(file.exists());
Driver d = null;
Class.forName("util.StubDriverDA");
d = DriverManager.getDriver(StubDriverDAURL);
DriverManager.deregisterDriver(d);
assertFalse(isDriverRegistered(d), "Driver is registered");
assertTrue(file.exists());
}
/**
* Create a PrintStream and use to send output via DriverManager.println
* Validate that if you disable the stream, the output sent is not present
*/
@Test
public void tests17() throws Exception {
ByteArrayOutputStream os = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(os);
DriverManager.setLogStream(ps);
assertTrue(DriverManager.getLogStream() == ps);
DriverManager.println(results[0]);
DriverManager.setLogStream((PrintStream) null);
assertTrue(DriverManager.getLogStream() == null);
DriverManager.println(noOutput);
DriverManager.setLogStream(ps);
DriverManager.println(results[1]);
DriverManager.println(results[2]);
DriverManager.println(results[3]);
DriverManager.setLogStream((PrintStream) null);
DriverManager.println(noOutput);
/*
* Check we do not get the output when the stream is disabled
*/
InputStreamReader is
= new InputStreamReader(new ByteArrayInputStream(os.toByteArray()));
BufferedReader reader = new BufferedReader(is);
for (String result : results) {
assertTrue(result.equals(reader.readLine()));
}
}
/**
* Create a PrintWriter and use it to send output via DriverManager.println
* Validate that if you disable the writer, the output sent is not present
*/
@Test
public void tests18() throws Exception {
CharArrayWriter cw = new CharArrayWriter();
PrintWriter pw = new PrintWriter(cw);
DriverManager.setLogWriter(pw);
assertTrue(DriverManager.getLogWriter() == pw);
DriverManager.println(results[0]);
DriverManager.setLogWriter(null);
assertTrue(DriverManager.getLogWriter() == null);
DriverManager.println(noOutput);
DriverManager.setLogWriter(pw);
DriverManager.println(results[1]);
DriverManager.println(results[2]);
DriverManager.println(results[3]);
DriverManager.setLogWriter(null);
DriverManager.println(noOutput);
/*
* Check we do not get the output when the stream is disabled
*/
BufferedReader reader
= new BufferedReader(new CharArrayReader(cw.toCharArray()));
for (String result : results) {
assertTrue(result.equals(reader.readLine()));
}
}
/**
* Register some driver implementations and validate that the driver
* elements covered by the Enumeration obtained from
* {@link DriverManager#getDrivers()} are the same as driver elements
* covered by the stream obtained from {@link DriverManager#drivers()}}
*/
@Test
public void tests19() throws Exception {
int n = 8;
for (int i = 0; i < n; i++) {
DriverManager.registerDriver(new StubDriver());
}
Collection<Driver> expectedDrivers = Collections.list(DriverManager.getDrivers());
assertEquals(n, expectedDrivers.size());
Collection<Driver> drivers = DriverManager.drivers().collect(Collectors.toList());
assertEquals(expectedDrivers, drivers);
}
}

View file

@ -0,0 +1,184 @@
/*
* Copyright (c) 2013, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package sql;
/*
* @test
* @bug 8007520
* @summary Test those bridge methods to/from java.time date/time classes
* @key randomness
*/
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.FieldSource;
import java.util.List;
import java.util.Random;
import java.sql.Timestamp;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.LocalDate;
import java.time.LocalTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.util.stream.IntStream;
import static org.junit.jupiter.api.Assertions.assertAll;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class JavatimeTest {
private static final int NANOS_PER_SECOND = 1000000000;
private static final long t1970 = new java.util.Date(70, 0, 01).getTime();
private static final Random R = new Random();
// Data provider contains 10,000 randomized arguments
// which are used as the dates and times for the tests
private static final List<Arguments> DATE_TIME_ARGS = IntStream.range(0, 10_000)
.mapToObj(i -> {
int days = R.nextInt(50) * 365 + R.nextInt(365);
long secs = t1970 + days * 86400 + R.nextInt(86400);
int nanos = R.nextInt(NANOS_PER_SECOND);
int nanos_ms = nanos / 1000000 * 1000000; // millis precision
long millis = secs * 1000 + R.nextInt(1000);
LocalDateTime ldt = LocalDateTime.ofEpochSecond(secs, nanos, ZoneOffset.UTC);
return Arguments.of(millis, nanos, ldt, secs, nanos_ms);
}).toList();
@ParameterizedTest(autoCloseArguments = false)
@FieldSource("DATE_TIME_ARGS")
void timestampTest(long millis, int nanos, LocalDateTime ldt, long secs) {
Timestamp ta = new Timestamp(millis);
ta.setNanos(nanos);
assertTrue(isEqual(ta.toLocalDateTime(), ta),
errMsg("j.s.ts -> ldt", millis, nanos, ldt, results(ta.toLocalDateTime(), ta)));
assertTrue(isEqual(ldt, Timestamp.valueOf(ldt)),
errMsg("ldt -> j.s.ts", millis, nanos, ldt, results(ldt, Timestamp.valueOf(ldt))));
Instant inst0 = ta.toInstant();
assertAll(errMsg("j.s.ts -> instant -> j.s.ts", millis, nanos, ldt),
() -> assertEquals(ta.getTime(), inst0.toEpochMilli()),
() -> assertEquals(ta.getNanos(), inst0.getNano()),
() -> assertEquals(ta, Timestamp.from(inst0))
);
Instant inst = Instant.ofEpochSecond(secs, nanos);
Timestamp ta0 = Timestamp.from(inst);
assertAll(errMsg("instant -> timestamp -> instant", millis, nanos, ldt),
() -> assertEquals(ta0.getTime(), inst.toEpochMilli()),
() -> assertEquals(ta0.getNanos(), inst.getNano()),
() -> assertEquals(inst, ta0.toInstant())
);
}
@ParameterizedTest(autoCloseArguments = false)
@FieldSource("DATE_TIME_ARGS")
void sqlDateTest(long millis, int nanos, LocalDateTime ldt) {
// j.s.d/t uses j.u.d.equals() !!!!!!!!
java.sql.Date jsd = new java.sql.Date(millis);
assertTrue(isEqual(jsd.toLocalDate(), jsd),
errMsg("j.s.d -> ld", millis, nanos, ldt, results(jsd.toLocalDate(), jsd)));
LocalDate ld = ldt.toLocalDate();
assertTrue(isEqual(ld, java.sql.Date.valueOf(ld)),
errMsg("ld -> j.s.d", millis, nanos, ldt, results(ld, java.sql.Date.valueOf(ld))));
}
@ParameterizedTest(autoCloseArguments = false)
@FieldSource("DATE_TIME_ARGS")
void sqlTimeTest(long millis, int nanos, LocalDateTime ldt, long secs, int nanos_ms) {
java.sql.Time jst = new java.sql.Time(millis);
assertTrue(isEqual(jst.toLocalTime(), jst),
errMsg("j.s.t -> lt", millis, nanos, ldt, results(jst.toLocalTime(), jst)));
// millis precision
LocalDateTime ldt_ms = LocalDateTime.ofEpochSecond(secs, nanos_ms, ZoneOffset.UTC);
LocalTime lt = ldt_ms.toLocalTime();
assertTrue(isEqual(lt, java.sql.Time.valueOf(lt)),
errMsg("lt -> j.s.t", millis, nanos, ldt, results(lt, java.sql.Time.valueOf(lt))));
}
private static boolean isEqual(LocalDateTime ldt, Timestamp ts) {
ZonedDateTime zdt = ZonedDateTime.of(ldt, ZoneId.systemDefault());
return zdt.getYear() == ts.getYear() + 1900 &&
zdt.getMonthValue() == ts.getMonth() + 1 &&
zdt.getDayOfMonth() == ts.getDate() &&
zdt.getHour() == ts.getHours() &&
zdt.getMinute() == ts.getMinutes() &&
zdt.getSecond() == ts.getSeconds() &&
zdt.getNano() == ts.getNanos();
}
private static String results(LocalDateTime ldt, Timestamp ts) {
ZonedDateTime zdt = ZonedDateTime.of(ldt, ZoneId.systemDefault());
return "ldt:ts %d/%d, %d/%d, %d/%d, %d/%d, %d/%d, %d/%d, nano:[%d/%d]%n".formatted(
zdt.getYear(), ts.getYear() + 1900,
zdt.getMonthValue(), ts.getMonth() + 1,
zdt.getDayOfMonth(), ts.getDate(),
zdt.getHour(), ts.getHours(),
zdt.getMinute(), ts.getMinutes(),
zdt.getSecond(), ts.getSeconds(),
zdt.getNano(), ts.getNanos());
}
private static boolean isEqual(LocalDate ld, java.sql.Date d) {
return ld.getYear() == d.getYear() + 1900 &&
ld.getMonthValue() == d.getMonth() + 1 &&
ld.getDayOfMonth() == d.getDate();
}
private static String results(LocalDate ld, java.sql.Date d) {
return "%d/%d, %d/%d, %d/%d%n".formatted(
ld.getYear(), d.getYear() + 1900,
ld.getMonthValue(), d.getMonth() + 1,
ld.getDayOfMonth(), d.getDate());
}
private static boolean isEqual(LocalTime lt, java.sql.Time t) {
return lt.getHour() == t.getHours() &&
lt.getMinute() == t.getMinutes() &&
lt.getSecond() == t.getSeconds();
}
private static String results(LocalTime lt, java.sql.Time t) {
return "%d/%d, %d/%d, %d/%d%n".formatted(
lt.getHour(), t.getHours(),
lt.getMinute(), t.getMinutes(),
lt.getSecond(), t.getSeconds());
}
private static String errMsg(String testCase, long millis, int nanos,
LocalDateTime ldt, String results) {
return "FAILED: %s%n INPUTS: ms: %16d ns: %10d ldt:[%s]%n ACTUAL: %s"
.formatted(testCase, millis, nanos, ldt, results);
}
private static String errMsg(String testCase, long millis, int nanos,
LocalDateTime ldt) {
return "FAILED: %s%n INPUTS: ms: %16d ns: %10d ldt:[%s]%n"
.formatted(testCase, millis, nanos, ldt);
}
}

View file

@ -0,0 +1,139 @@
/*
* Copyright (c) 2015, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package sql;
import org.junit.jupiter.params.provider.ValueSource;
import util.BaseTest;
import util.StubConnection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import org.junit.jupiter.api.AfterEach;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
public class PreparedStatementTests extends BaseTest {
private PreparedStatement pstmt;
@BeforeEach
public void setUpMethod() throws Exception {
pstmt = new StubConnection().prepareStatement("Select * from foo were bar = ?");
}
@AfterEach
public void tearDownMethod() throws Exception {
pstmt.close();
}
/*
* Verify that enquoteLiteral creates a valid literal and converts every
* single quote to two single quotes
*/
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("validEnquotedLiteralValues")
public void test00(String s, String expected) throws SQLException {
assertEquals(expected, pstmt.enquoteLiteral(s));
}
/*
* Validate a NullPointerException is thrown if the string passed to
* enquoteLiteral is null
*/
@Test
public void test01() throws SQLException {
assertThrows(NullPointerException.class, () -> pstmt.enquoteLiteral(null));
}
/*
* Validate that enquoteIdentifier returns the expected value
*/
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("validEnquotedIdentifierValues")
public void test02(String s, boolean alwaysQuote, String expected) throws SQLException {
assertEquals(expected, pstmt.enquoteIdentifier(s, alwaysQuote));
}
/*
* Validate that a SQLException is thrown for values that are not valid
* for a SQL identifier
*/
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("invalidEnquotedIdentifierValues")
public void test03(String s, boolean alwaysQuote) throws SQLException {
assertThrows(SQLException.class, () -> pstmt.enquoteIdentifier(s, alwaysQuote));
}
/*
* Validate a NullPointerException is thrown is the string passed to
* enquoteIdentiifer is null
*/
@ParameterizedTest(autoCloseArguments = false)
@ValueSource(booleans = {true, false})
public void test04(boolean alwaysQuote) throws SQLException {
assertThrows(NullPointerException.class, () -> pstmt.enquoteIdentifier(null, alwaysQuote));
}
/*
* Validate that isSimpleIdentifier returns the expected value
*/
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("simpleIdentifierValues")
public void test05(String s, boolean expected) throws SQLException {
assertEquals(expected, pstmt.isSimpleIdentifier(s));
}
/*
* Validate a NullPointerException is thrown if the string passed to
* isSimpleIdentifier is null
*/
@Test
public void test06() throws SQLException {
assertThrows(NullPointerException.class, () -> pstmt.isSimpleIdentifier(null));
}
/*
* Verify that enquoteLiteral creates a valid literal and converts every
* single quote to two single quotes
*/
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("validEnquotedNCharLiteralValues")
public void test07(String s, String expected) throws SQLException {
assertEquals(expected, pstmt.enquoteNCharLiteral(s));
}
/*
* Validate a NullPointerException is thrown if the string passed to
* enquoteNCharLiteral is null
*/
@Test
public void test08() throws SQLException {
assertThrows(NullPointerException.class, () -> pstmt.enquoteNCharLiteral(null));
}
}

View file

@ -0,0 +1,229 @@
/*
* Copyright (c) 2014, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package sql;
import java.sql.ClientInfoStatus;
import java.sql.SQLClientInfoException;
import java.sql.SQLException;
import java.util.HashMap;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
import util.BaseTest;
public class SQLClientInfoExceptionTests extends BaseTest {
private final HashMap<String, ClientInfoStatus> map = new HashMap<>();
public SQLClientInfoExceptionTests() {
map.put("1", ClientInfoStatus.REASON_UNKNOWN_PROPERTY);
map.put("21", ClientInfoStatus.REASON_UNKNOWN_PROPERTY);
}
/**
* Create SQLClientInfoException and setting all objects to null
*/
@Test
public void test() {
SQLClientInfoException e = new SQLClientInfoException(null);
assertTrue(e.getMessage() == null && e.getSQLState() == null
&& e.getCause() == null && e.getErrorCode() == 0
&& e.getFailedProperties() == null);
}
/**
* Create SQLClientInfoException with no-arg constructor
*/
@Test
public void test1() {
SQLClientInfoException ex = new SQLClientInfoException();
assertTrue(ex.getMessage() == null
&& ex.getSQLState() == null
&& ex.getCause() == null
&& ex.getErrorCode() == 0
&& ex.getFailedProperties() == null);
}
/**
* Create SQLClientInfoException with null Throwable
*/
@Test
public void test2() {
SQLClientInfoException ex = new SQLClientInfoException(map, null);
assertTrue(ex.getMessage() == null
&& ex.getSQLState() == null
&& ex.getCause() == null
&& ex.getErrorCode() == 0
&& ex.getFailedProperties().equals(map));
}
/**
* Create SQLClientInfoException with message
*/
@Test
public void test3() {
SQLClientInfoException ex = new SQLClientInfoException(reason, map);
assertTrue(ex.getMessage().equals(reason)
&& ex.getSQLState() == null
&& ex.getCause() == null
&& ex.getErrorCode() == 0
&& ex.getFailedProperties().equals(map));
}
/**
* Create SQLClientInfoException with null Throwable
*/
@Test
public void test4() {
SQLClientInfoException ex = new SQLClientInfoException(reason, map, null);
assertTrue(ex.getMessage().equals(reason)
&& ex.getSQLState() == null
&& ex.getCause() == null
&& ex.getErrorCode() == 0
&& ex.getFailedProperties().equals(map));
}
/**
* Create SQLClientInfoException with message, and SQLState
*/
@Test
public void test5() {
SQLClientInfoException ex = new SQLClientInfoException(reason, state,
map);
assertTrue(ex.getMessage().equals(reason)
&& ex.getSQLState().equals(state)
&& ex.getCause() == null
&& ex.getErrorCode() == 0
&& ex.getFailedProperties().equals(map));
}
/**
* Create SQLClientInfoException with message, and SQLState
*/
@Test
public void test6() {
SQLClientInfoException ex = new SQLClientInfoException(reason, state,
map, t);
assertTrue(ex.getMessage().equals(reason)
&& ex.getSQLState().equals(state)
&& cause.equals(ex.getCause().toString())
&& ex.getErrorCode() == 0
&& ex.getFailedProperties().equals(map));
}
/**
* Create SQLClientInfoException with message, SQLState, errorCode, and
* Throwable
*/
@Test
public void test7() {
SQLClientInfoException ex = new SQLClientInfoException(reason, state,
errorCode, map);
assertTrue(ex.getMessage().equals(reason)
&& ex.getSQLState().equals(state)
&& ex.getCause() == null
&& ex.getErrorCode() == errorCode
&& ex.getFailedProperties().equals(map));
}
/**
* Create SQLClientInfoException with message, SQLState, and error code
*/
@Test
public void test8() {
SQLClientInfoException ex = new SQLClientInfoException(reason, state,
errorCode, map, t);
assertTrue(ex.getMessage().equals(reason)
&& ex.getSQLState().equals(state)
&& cause.equals(ex.getCause().toString())
&& ex.getErrorCode() == errorCode
&& ex.getFailedProperties().equals(map));
}
/**
* Serialize a SQLClientInfoException and make sure you can read it back
* properly
*/
@Test
public void test10() throws Exception {
SQLClientInfoException e = new SQLClientInfoException(reason, state,
errorCode, map, t);
SQLClientInfoException ex1 =
createSerializedException(e);
assertTrue(reason.equals(ex1.getMessage())
&& ex1.getSQLState().equals(state)
&& cause.equals(ex1.getCause().toString())
&& ex1.getErrorCode() == errorCode
&& ex1.getFailedProperties().equals(map));
}
/**
* Validate that the ordering of the returned Exceptions is correct using
* for-each loop
*/
@Test
public void test11() {
SQLClientInfoException ex = new SQLClientInfoException("Exception 1",
map, t1);
SQLClientInfoException ex1 = new SQLClientInfoException("Exception 2",
map);
SQLClientInfoException ex2 = new SQLClientInfoException("Exception 3",
map, t2);
ex.setNextException(ex1);
ex.setNextException(ex2);
int num = 0;
for (Throwable e : ex) {
assertTrue(msgs[num++].equals(e.getMessage()));
}
}
/**
* Validate that the ordering of the returned Exceptions is correct using
* traditional while loop
*/
@Test
public void test12() {
SQLClientInfoException ex = new SQLClientInfoException("Exception 1",
map, t1);
SQLClientInfoException ex1 = new SQLClientInfoException("Exception 2",
map);
SQLClientInfoException ex2 = new SQLClientInfoException("Exception 3",
map, t2);
ex.setNextException(ex1);
ex.setNextException(ex2);
int num = 0;
SQLException sqe = ex;
while (sqe != null) {
assertTrue(msgs[num++].equals(sqe.getMessage()));
Throwable c = sqe.getCause();
while (c != null) {
assertTrue(msgs[num++].equals(c.getMessage()));
c = c.getCause();
}
sqe = sqe.getNextException();
}
}
}

View file

@ -0,0 +1,217 @@
/*
* Copyright (c) 2014, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package sql;
import java.sql.SQLDataException;
import java.sql.SQLException;
import java.sql.SQLNonTransientException;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
import util.BaseTest;
public class SQLDataExceptionTests extends BaseTest {
/**
* Create SQLDataException and setting all objects to null
*/
@Test
public void test() {
SQLDataException e = new SQLDataException(null, null, errorCode, null);
assertTrue(e.getMessage() == null && e.getSQLState() == null
&& e.getCause() == null && e.getErrorCode() == errorCode);
}
/**
* Create SQLDataException with no-arg constructor
*/
@Test
public void test1() {
SQLDataException ex = new SQLDataException();
assertTrue(ex.getMessage() == null
&& ex.getSQLState() == null
&& ex.getCause() == null
&& ex.getErrorCode() == 0);
}
/**
* Create SQLDataException with message
*/
@Test
public void test2() {
SQLDataException ex = new SQLDataException(reason);
assertTrue(ex.getMessage().equals(reason)
&& ex.getSQLState() == null
&& ex.getCause() == null
&& ex.getErrorCode() == 0);
}
/**
* Create SQLDataException with message, and SQLState
*/
@Test
public void test3() {
SQLDataException ex = new SQLDataException(reason, state);
assertTrue(ex.getMessage().equals(reason)
&& ex.getSQLState().equals(state)
&& ex.getCause() == null
&& ex.getErrorCode() == 0);
}
/**
* Create SQLDataException with message, SQLState, and error code
*/
@Test
public void test4() {
SQLDataException ex = new SQLDataException(reason, state, errorCode);
assertTrue(ex.getMessage().equals(reason)
&& ex.getSQLState().equals(state)
&& ex.getCause() == null
&& ex.getErrorCode() == errorCode);
}
/**
* Create SQLDataException with message, SQLState, errorCode, and Throwable
*/
@Test
public void test5() {
SQLDataException ex = new SQLDataException(reason, state, errorCode, t);
assertTrue(ex.getMessage().equals(reason)
&& ex.getSQLState().equals(state)
&& cause.equals(ex.getCause().toString())
&& ex.getErrorCode() == errorCode);
}
/**
* Create SQLDataException with message, SQLState, and Throwable
*/
@Test
public void test6() {
SQLDataException ex = new SQLDataException(reason, state, t);
assertTrue(ex.getMessage().equals(reason)
&& ex.getSQLState().equals(state)
&& cause.equals(ex.getCause().toString())
&& ex.getErrorCode() == 0);
}
/**
* Create SQLDataException with message, and Throwable
*/
@Test
public void test7() {
SQLDataException ex = new SQLDataException(reason, t);
assertTrue(ex.getMessage().equals(reason)
&& ex.getSQLState() == null
&& cause.equals(ex.getCause().toString())
&& ex.getErrorCode() == 0);
}
/**
* Create SQLDataException with null Throwable
*/
@Test
public void test8() {
SQLDataException ex = new SQLDataException((Throwable)null);
assertTrue(ex.getMessage() == null
&& ex.getSQLState() == null
&& ex.getCause() == null
&& ex.getErrorCode() == 0);
}
/**
* Create SQLDataException with Throwable
*/
@Test
public void test9() {
SQLDataException ex = new SQLDataException(t);
assertTrue(ex.getMessage().equals(cause)
&& ex.getSQLState() == null
&& cause.equals(ex.getCause().toString())
&& ex.getErrorCode() == 0);
}
/**
* Serialize a SQLDataException and make sure you can read it back properly
*/
@Test
public void test10() throws Exception {
SQLDataException e = new SQLDataException(reason, state, errorCode, t);
SQLDataException ex1 = createSerializedException(e);
assertTrue(reason.equals(ex1.getMessage())
&& ex1.getSQLState().equals(state)
&& cause.equals(ex1.getCause().toString())
&& ex1.getErrorCode() == errorCode);
}
/**
* Validate that the ordering of the returned Exceptions is correct
* using for-each loop
*/
@Test
public void test11() {
SQLDataException ex = new SQLDataException("Exception 1", t1);
SQLDataException ex1 = new SQLDataException("Exception 2");
SQLDataException ex2 = new SQLDataException("Exception 3", t2);
ex.setNextException(ex1);
ex.setNextException(ex2);
int num = 0;
for (Throwable e : ex) {
assertTrue(msgs[num++].equals(e.getMessage()));
}
}
/**
* Validate that the ordering of the returned Exceptions is correct
* using traditional while loop
*/
@Test
public void test12() {
SQLDataException ex = new SQLDataException("Exception 1", t1);
SQLDataException ex1 = new SQLDataException("Exception 2");
SQLDataException ex2 = new SQLDataException("Exception 3", t2);
ex.setNextException(ex1);
ex.setNextException(ex2);
int num = 0;
SQLException sqe = ex;
while (sqe != null) {
assertTrue(msgs[num++].equals(sqe.getMessage()));
Throwable c = sqe.getCause();
while (c != null) {
assertTrue(msgs[num++].equals(c.getMessage()));
c = c.getCause();
}
sqe = sqe.getNextException();
}
}
/**
* Create SQLDataException and validate it is an instance of
* SQLNonTransientException
*/
@Test
public void test13() {
Exception ex = new SQLDataException();
assertTrue(ex instanceof SQLNonTransientException);
}
}

View file

@ -0,0 +1,204 @@
/*
* Copyright (c) 2014, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package sql;
import java.sql.SQLException;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
import util.BaseTest;
public class SQLExceptionTests extends BaseTest {
/**
* Create SQLException and setting all objects to null
*/
@Test
public void test() {
SQLException e = new SQLException(null, null, errorCode, null);
assertTrue(e.getMessage() == null && e.getSQLState() == null
&& e.getCause() == null && e.getErrorCode() == errorCode);
}
/**
* Create SQLException with no-arg constructor
*/
@Test
public void test1() {
SQLException ex = new SQLException();
assertTrue(ex.getMessage() == null
&& ex.getSQLState() == null
&& ex.getCause() == null
&& ex.getErrorCode() == 0);
}
/**
* Create SQLException with message
*/
@Test
public void test2() {
SQLException ex = new SQLException(reason);
assertTrue(ex.getMessage().equals(reason)
&& ex.getSQLState() == null
&& ex.getCause() == null
&& ex.getErrorCode() == 0);
}
/**
* Create SQLException with message, and SQLState
*/
@Test
public void test3() {
SQLException ex = new SQLException(reason, state);
assertTrue(ex.getMessage().equals(reason)
&& ex.getSQLState().equals(state)
&& ex.getCause() == null
&& ex.getErrorCode() == 0);
}
/**
* Create SQLException with message, SQLState, and error code
*/
@Test
public void test4() {
SQLException ex = new SQLException(reason, state, errorCode);
assertTrue(ex.getMessage().equals(reason)
&& ex.getSQLState().equals(state)
&& ex.getCause() == null
&& ex.getErrorCode() == errorCode);
}
/**
* Create SQLException with message, SQLState, errorCode, and Throwable
*/
@Test
public void test5() {
SQLException ex = new SQLException(reason, state, errorCode, t);
assertTrue(ex.getMessage().equals(reason)
&& ex.getSQLState().equals(state)
&& cause.equals(ex.getCause().toString())
&& ex.getErrorCode() == errorCode);
}
/**
* Create SQLException with message, SQLState, and Throwable
*/
@Test
public void test6() {
SQLException ex = new SQLException(reason, state, t);
assertTrue(ex.getMessage().equals(reason)
&& ex.getSQLState().equals(state)
&& cause.equals(ex.getCause().toString())
&& ex.getErrorCode() == 0);
}
/**
* Create SQLException with message, and Throwable
*/
@Test
public void test7() {
SQLException ex = new SQLException(reason, t);
assertTrue(ex.getMessage().equals(reason)
&& ex.getSQLState() == null
&& cause.equals(ex.getCause().toString())
&& ex.getErrorCode() == 0);
}
/**
* Create SQLException with null Throwable
*/
@Test
public void test8() {
SQLException ex = new SQLException((Throwable)null);
assertTrue(ex.getMessage() == null
&& ex.getSQLState() == null
&& ex.getCause() == null
&& ex.getErrorCode() == 0);
}
/**
* Create SQLException with Throwable
*/
@Test
public void test9() {
SQLException ex = new SQLException(t);
assertTrue(ex.getMessage().equals(cause)
&& ex.getSQLState() == null
&& cause.equals(ex.getCause().toString())
&& ex.getErrorCode() == 0);
}
/**
* Serialize a SQLException and make sure you can read it back properly
*/
@Test
public void test10() throws Exception {
SQLException e = new SQLException(reason, state, errorCode, t);
SQLException ex1 = createSerializedException(e);
assertTrue(reason.equals(ex1.getMessage())
&& ex1.getSQLState().equals(state)
&& cause.equals(ex1.getCause().toString())
&& ex1.getErrorCode() == errorCode);
}
/**
* Validate that the ordering of the returned Exceptions is correct
* using for-each loop
*/
@Test
public void test11() {
SQLException ex = new SQLException("Exception 1", t1);
SQLException ex1 = new SQLException("Exception 2");
SQLException ex2 = new SQLException("Exception 3", t2);
ex.setNextException(ex1);
ex.setNextException(ex2);
int num = 0;
for (Throwable e : ex) {
assertTrue(msgs[num++].equals(e.getMessage()));
}
}
/**
* Validate that the ordering of the returned Exceptions is correct
* using traditional while loop
*/
@Test
public void test12() {
SQLException ex = new SQLException("Exception 1", t1);
SQLException ex1 = new SQLException("Exception 2");
SQLException ex2 = new SQLException("Exception 3", t2);
ex.setNextException(ex1);
ex.setNextException(ex2);
int num = 0;
while (ex != null) {
assertTrue(msgs[num++].equals(ex.getMessage()));
Throwable c = ex.getCause();
while (c != null) {
assertTrue(msgs[num++].equals(c.getMessage()));
c = c.getCause();
}
ex = ex.getNextException();
}
}
}

View file

@ -0,0 +1,234 @@
/*
* Copyright (c) 2014, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package sql;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.sql.SQLNonTransientException;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
import util.BaseTest;
public class SQLFeatureNotSupportedExceptionTests extends BaseTest {
/**
* Create SQLFeatureNotSupportedException and setting all objects to null
*/
@Test
public void test() {
SQLFeatureNotSupportedException e =
new SQLFeatureNotSupportedException(null, null, errorCode, null);
assertTrue(e.getMessage() == null && e.getSQLState() == null
&& e.getCause() == null && e.getErrorCode() == errorCode);
}
/**
* Create SQLFeatureNotSupportedException with no-arg constructor
*/
@Test
public void test1() {
SQLFeatureNotSupportedException ex = new SQLFeatureNotSupportedException();
assertTrue(ex.getMessage() == null
&& ex.getSQLState() == null
&& ex.getCause() == null
&& ex.getErrorCode() == 0);
}
/**
* Create SQLFeatureNotSupportedException with message
*/
@Test
public void test2() {
SQLFeatureNotSupportedException ex =
new SQLFeatureNotSupportedException(reason);
assertTrue(ex.getMessage().equals(reason)
&& ex.getSQLState() == null
&& ex.getCause() == null
&& ex.getErrorCode() == 0);
}
/**
* Create SQLFeatureNotSupportedException with message, and SQLState
*/
@Test
public void test3() {
SQLFeatureNotSupportedException ex =
new SQLFeatureNotSupportedException(reason, state);
assertTrue(ex.getMessage().equals(reason)
&& ex.getSQLState().equals(state)
&& ex.getCause() == null
&& ex.getErrorCode() == 0);
}
/**
* Create SQLFeatureNotSupportedException with message, SQLState, and error code
*/
@Test
public void test4() {
SQLFeatureNotSupportedException ex =
new SQLFeatureNotSupportedException(reason, state, errorCode);
assertTrue(ex.getMessage().equals(reason)
&& ex.getSQLState().equals(state)
&& ex.getCause() == null
&& ex.getErrorCode() == errorCode);
}
/**
* Create SQLFeatureNotSupportedException with message, SQLState, errorCode, and Throwable
*/
@Test
public void test5() {
SQLFeatureNotSupportedException ex =
new SQLFeatureNotSupportedException(reason, state, errorCode, t);
assertTrue(ex.getMessage().equals(reason)
&& ex.getSQLState().equals(state)
&& cause.equals(ex.getCause().toString())
&& ex.getErrorCode() == errorCode);
}
/**
* Create SQLFeatureNotSupportedException with message, SQLState, and Throwable
*/
@Test
public void test6() {
SQLFeatureNotSupportedException ex =
new SQLFeatureNotSupportedException(reason, state, t);
assertTrue(ex.getMessage().equals(reason)
&& ex.getSQLState().equals(state)
&& cause.equals(ex.getCause().toString())
&& ex.getErrorCode() == 0);
}
/**
* Create SQLFeatureNotSupportedException with message, and Throwable
*/
@Test
public void test7() {
SQLFeatureNotSupportedException ex =
new SQLFeatureNotSupportedException(reason, t);
assertTrue(ex.getMessage().equals(reason)
&& ex.getSQLState() == null
&& cause.equals(ex.getCause().toString())
&& ex.getErrorCode() == 0);
}
/**
* Create SQLFeatureNotSupportedException with null Throwable
*/
@Test
public void test8() {
SQLFeatureNotSupportedException ex =
new SQLFeatureNotSupportedException((Throwable) null);
assertTrue(ex.getMessage() == null
&& ex.getSQLState() == null
&& ex.getCause() == null
&& ex.getErrorCode() == 0);
}
/**
* Create SQLFeatureNotSupportedException with Throwable
*/
@Test
public void test9() {
SQLFeatureNotSupportedException ex =
new SQLFeatureNotSupportedException(t);
assertTrue(ex.getMessage().equals(cause)
&& ex.getSQLState() == null
&& cause.equals(ex.getCause().toString())
&& ex.getErrorCode() == 0);
}
/**
* Serialize a SQLFeatureNotSupportedException and make sure you can read it back properly
*/
@Test
public void test10() throws Exception {
SQLFeatureNotSupportedException e =
new SQLFeatureNotSupportedException(reason, state, errorCode, t);
SQLFeatureNotSupportedException ex1 =
createSerializedException(e);
assertTrue(reason.equals(ex1.getMessage())
&& ex1.getSQLState().equals(state)
&& cause.equals(ex1.getCause().toString())
&& ex1.getErrorCode() == errorCode);
}
/**
* Validate that the ordering of the returned Exceptions is correct
* using for-each loop
*/
@Test
public void test11() {
SQLFeatureNotSupportedException ex =
new SQLFeatureNotSupportedException("Exception 1", t1);
SQLFeatureNotSupportedException ex1 =
new SQLFeatureNotSupportedException("Exception 2");
SQLFeatureNotSupportedException ex2 =
new SQLFeatureNotSupportedException("Exception 3", t2);
ex.setNextException(ex1);
ex.setNextException(ex2);
int num = 0;
for (Throwable e : ex) {
assertTrue(msgs[num++].equals(e.getMessage()));
}
}
/**
* Validate that the ordering of the returned Exceptions is correct
* using traditional while loop
*/
@Test
public void test12() {
SQLFeatureNotSupportedException ex =
new SQLFeatureNotSupportedException("Exception 1", t1);
SQLFeatureNotSupportedException ex1 =
new SQLFeatureNotSupportedException("Exception 2");
SQLFeatureNotSupportedException ex2 =
new SQLFeatureNotSupportedException("Exception 3", t2);
ex.setNextException(ex1);
ex.setNextException(ex2);
int num = 0;
SQLException sqe = ex;
while (sqe != null) {
assertTrue(msgs[num++].equals(sqe.getMessage()));
Throwable c = sqe.getCause();
while (c != null) {
assertTrue(msgs[num++].equals(c.getMessage()));
c = c.getCause();
}
sqe = sqe.getNextException();
}
}
/**
* Create SQLFeatureNotSupportedException and validate it is an instance of
* SQLNonTransientException
*/
@Test
public void test13() {
Exception ex = new SQLFeatureNotSupportedException();
assertTrue(ex instanceof SQLNonTransientException);
}
}

View file

@ -0,0 +1,237 @@
/*
* Copyright (c) 2014, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package sql;
import java.sql.SQLException;
import java.sql.SQLIntegrityConstraintViolationException;
import java.sql.SQLNonTransientException;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
import util.BaseTest;
public class SQLIntegrityConstraintViolationExceptionTests extends BaseTest {
/**
* Create SQLIntegrityConstraintViolationException and setting all objects to null
*/
@Test
public void test() {
SQLIntegrityConstraintViolationException e =
new SQLIntegrityConstraintViolationException(null,
null, errorCode, null);
assertTrue(e.getMessage() == null && e.getSQLState() == null
&& e.getCause() == null && e.getErrorCode() == errorCode);
}
/**
* Create SQLIntegrityConstraintViolationException with no-arg constructor
*/
@Test
public void test1() {
SQLIntegrityConstraintViolationException ex =
new SQLIntegrityConstraintViolationException();
assertTrue(ex.getMessage() == null
&& ex.getSQLState() == null
&& ex.getCause() == null
&& ex.getErrorCode() == 0);
}
/**
* Create SQLIntegrityConstraintViolationException with message
*/
@Test
public void test2() {
SQLIntegrityConstraintViolationException ex =
new SQLIntegrityConstraintViolationException(reason);
assertTrue(ex.getMessage().equals(reason)
&& ex.getSQLState() == null
&& ex.getCause() == null
&& ex.getErrorCode() == 0);
}
/**
* Create SQLIntegrityConstraintViolationException with message, and SQLState
*/
@Test
public void test3() {
SQLIntegrityConstraintViolationException ex =
new SQLIntegrityConstraintViolationException(reason, state);
assertTrue(ex.getMessage().equals(reason)
&& ex.getSQLState().equals(state)
&& ex.getCause() == null
&& ex.getErrorCode() == 0);
}
/**
* Create SQLIntegrityConstraintViolationException with message, SQLState, and error code
*/
@Test
public void test4() {
SQLIntegrityConstraintViolationException ex =
new SQLIntegrityConstraintViolationException(reason, state, errorCode);
assertTrue(ex.getMessage().equals(reason)
&& ex.getSQLState().equals(state)
&& ex.getCause() == null
&& ex.getErrorCode() == errorCode);
}
/**
* Create SQLIntegrityConstraintViolationException with message, SQLState, errorCode, and Throwable
*/
@Test
public void test5() {
SQLIntegrityConstraintViolationException ex =
new SQLIntegrityConstraintViolationException(reason, state, errorCode, t);
assertTrue(ex.getMessage().equals(reason)
&& ex.getSQLState().equals(state)
&& cause.equals(ex.getCause().toString())
&& ex.getErrorCode() == errorCode);
}
/**
* Create SQLIntegrityConstraintViolationException with message, SQLState, and Throwable
*/
@Test
public void test6() {
SQLIntegrityConstraintViolationException ex =
new SQLIntegrityConstraintViolationException(reason, state, t);
assertTrue(ex.getMessage().equals(reason)
&& ex.getSQLState().equals(state)
&& cause.equals(ex.getCause().toString())
&& ex.getErrorCode() == 0);
}
/**
* Create SQLIntegrityConstraintViolationException with message, and Throwable
*/
@Test
public void test7() {
SQLIntegrityConstraintViolationException ex =
new SQLIntegrityConstraintViolationException(reason, t);
assertTrue(ex.getMessage().equals(reason)
&& ex.getSQLState() == null
&& cause.equals(ex.getCause().toString())
&& ex.getErrorCode() == 0);
}
/**
* Create SQLIntegrityConstraintViolationException with null Throwable
*/
@Test
public void test8() {
SQLIntegrityConstraintViolationException ex =
new SQLIntegrityConstraintViolationException((Throwable)null);
assertTrue(ex.getMessage() == null
&& ex.getSQLState() == null
&& ex.getCause() == null
&& ex.getErrorCode() == 0);
}
/**
* Create SQLIntegrityConstraintViolationException with Throwable
*/
@Test
public void test9() {
SQLIntegrityConstraintViolationException ex =
new SQLIntegrityConstraintViolationException(t);
assertTrue(ex.getMessage().equals(cause)
&& ex.getSQLState() == null
&& cause.equals(ex.getCause().toString())
&& ex.getErrorCode() == 0);
}
/**
* Serialize a SQLIntegrityConstraintViolationException and make sure
* you can read it back properly
*/
@Test
public void test10() throws Exception {
SQLIntegrityConstraintViolationException e =
new SQLIntegrityConstraintViolationException(reason, state, errorCode, t);
SQLIntegrityConstraintViolationException ex1 =
createSerializedException(e);
assertTrue(reason.equals(ex1.getMessage())
&& ex1.getSQLState().equals(state)
&& cause.equals(ex1.getCause().toString())
&& ex1.getErrorCode() == errorCode);
}
/**
* Validate that the ordering of the returned Exceptions is correct
* using for-each loop
*/
@Test
public void test11() {
SQLIntegrityConstraintViolationException ex =
new SQLIntegrityConstraintViolationException("Exception 1", t1);
SQLIntegrityConstraintViolationException ex1 =
new SQLIntegrityConstraintViolationException("Exception 2");
SQLIntegrityConstraintViolationException ex2 =
new SQLIntegrityConstraintViolationException("Exception 3", t2);
ex.setNextException(ex1);
ex.setNextException(ex2);
int num = 0;
for (Throwable e : ex) {
assertTrue(msgs[num++].equals(e.getMessage()));
}
}
/**
* Validate that the ordering of the returned Exceptions is correct
* using traditional while loop
*/
@Test
public void test12() {
SQLIntegrityConstraintViolationException ex =
new SQLIntegrityConstraintViolationException("Exception 1", t1);
SQLIntegrityConstraintViolationException ex1 =
new SQLIntegrityConstraintViolationException("Exception 2");
SQLIntegrityConstraintViolationException ex2 =
new SQLIntegrityConstraintViolationException("Exception 3", t2);
ex.setNextException(ex1);
ex.setNextException(ex2);
int num = 0;
SQLException sqe = ex;
while (sqe != null) {
assertTrue(msgs[num++].equals(sqe.getMessage()));
Throwable c = sqe.getCause();
while (c != null) {
assertTrue(msgs[num++].equals(c.getMessage()));
c = c.getCause();
}
sqe = sqe.getNextException();
}
}
/**
* Create SQLIntegrityConstraintViolationException and validate it is an instance of
* SQLNonTransientException
*/
@Test
public void test13() {
Exception ex = new SQLIntegrityConstraintViolationException();
assertTrue(ex instanceof SQLNonTransientException);
}
}

View file

@ -0,0 +1,241 @@
/*
* Copyright (c) 2014, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package sql;
import java.sql.SQLException;
import java.sql.SQLInvalidAuthorizationSpecException;
import java.sql.SQLNonTransientException;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
import util.BaseTest;
public class SQLInvalidAuthorizationSpecExceptionTests extends BaseTest {
/**
* Create SQLInvalidAuthorizationSpecException and setting all objects to
* null
*/
@Test
public void test() {
SQLInvalidAuthorizationSpecException e
= new SQLInvalidAuthorizationSpecException(null,
null, errorCode, null);
assertTrue(e.getMessage() == null && e.getSQLState() == null
&& e.getCause() == null && e.getErrorCode() == errorCode);
}
/**
* Create SQLInvalidAuthorizationSpecException with no-arg constructor
*/
@Test
public void test1() {
SQLInvalidAuthorizationSpecException ex
= new SQLInvalidAuthorizationSpecException();
assertTrue(ex.getMessage() == null
&& ex.getSQLState() == null
&& ex.getCause() == null
&& ex.getErrorCode() == 0);
}
/**
* Create SQLInvalidAuthorizationSpecException with message
*/
@Test
public void test2() {
SQLInvalidAuthorizationSpecException ex
= new SQLInvalidAuthorizationSpecException(reason);
assertTrue(ex.getMessage().equals(reason)
&& ex.getSQLState() == null
&& ex.getCause() == null
&& ex.getErrorCode() == 0);
}
/**
* Create SQLInvalidAuthorizationSpecException with message, and SQLState
*/
@Test
public void test3() {
SQLInvalidAuthorizationSpecException ex
= new SQLInvalidAuthorizationSpecException(reason, state);
assertTrue(ex.getMessage().equals(reason)
&& ex.getSQLState().equals(state)
&& ex.getCause() == null
&& ex.getErrorCode() == 0);
}
/**
* Create SQLInvalidAuthorizationSpecException with message, SQLState, and
* error code
*/
@Test
public void test4() {
SQLInvalidAuthorizationSpecException ex
= new SQLInvalidAuthorizationSpecException(reason, state, errorCode);
assertTrue(ex.getMessage().equals(reason)
&& ex.getSQLState().equals(state)
&& ex.getCause() == null
&& ex.getErrorCode() == errorCode);
}
/**
* Create SQLInvalidAuthorizationSpecException with message, SQLState,
* errorCode, and Throwable
*/
@Test
public void test5() {
SQLInvalidAuthorizationSpecException ex
= new SQLInvalidAuthorizationSpecException(reason, state, errorCode, t);
assertTrue(ex.getMessage().equals(reason)
&& ex.getSQLState().equals(state)
&& cause.equals(ex.getCause().toString())
&& ex.getErrorCode() == errorCode);
}
/**
* Create SQLInvalidAuthorizationSpecException with message, SQLState, and
* Throwable
*/
@Test
public void test6() {
SQLInvalidAuthorizationSpecException ex
= new SQLInvalidAuthorizationSpecException(reason, state, t);
assertTrue(ex.getMessage().equals(reason)
&& ex.getSQLState().equals(state)
&& cause.equals(ex.getCause().toString())
&& ex.getErrorCode() == 0);
}
/**
* Create SQLInvalidAuthorizationSpecException with message, and Throwable
*/
@Test
public void test7() {
SQLInvalidAuthorizationSpecException ex
= new SQLInvalidAuthorizationSpecException(reason, t);
assertTrue(ex.getMessage().equals(reason)
&& ex.getSQLState() == null
&& cause.equals(ex.getCause().toString())
&& ex.getErrorCode() == 0);
}
/**
* Create SQLInvalidAuthorizationSpecException with null Throwable
*/
@Test
public void test8() {
SQLInvalidAuthorizationSpecException ex
= new SQLInvalidAuthorizationSpecException((Throwable) null);
assertTrue(ex.getMessage() == null
&& ex.getSQLState() == null
&& ex.getCause() == null
&& ex.getErrorCode() == 0);
}
/**
* Create SQLInvalidAuthorizationSpecException with Throwable
*/
@Test
public void test9() {
SQLInvalidAuthorizationSpecException ex
= new SQLInvalidAuthorizationSpecException(t);
assertTrue(ex.getMessage().equals(cause)
&& ex.getSQLState() == null
&& cause.equals(ex.getCause().toString())
&& ex.getErrorCode() == 0);
}
/**
* Serialize a SQLInvalidAuthorizationSpecException and make sure you can
* read it back properly
*/
@Test
public void test10() throws Exception {
SQLInvalidAuthorizationSpecException e
= new SQLInvalidAuthorizationSpecException(reason, state, errorCode, t);
SQLInvalidAuthorizationSpecException ex1 =
createSerializedException(e);
assertTrue(reason.equals(ex1.getMessage())
&& ex1.getSQLState().equals(state)
&& cause.equals(ex1.getCause().toString())
&& ex1.getErrorCode() == errorCode);
}
/**
* Validate that the ordering of the returned Exceptions is correct using
* for-each loop
*/
@Test
public void test11() {
SQLInvalidAuthorizationSpecException ex
= new SQLInvalidAuthorizationSpecException("Exception 1", t1);
SQLInvalidAuthorizationSpecException ex1
= new SQLInvalidAuthorizationSpecException("Exception 2");
SQLInvalidAuthorizationSpecException ex2
= new SQLInvalidAuthorizationSpecException("Exception 3", t2);
ex.setNextException(ex1);
ex.setNextException(ex2);
int num = 0;
for (Throwable e : ex) {
assertTrue(msgs[num++].equals(e.getMessage()));
}
}
/**
* Validate that the ordering of the returned Exceptions is correct using
* traditional while loop
*/
@Test
public void test12() {
SQLInvalidAuthorizationSpecException ex
= new SQLInvalidAuthorizationSpecException("Exception 1", t1);
SQLInvalidAuthorizationSpecException ex1
= new SQLInvalidAuthorizationSpecException("Exception 2");
SQLInvalidAuthorizationSpecException ex2
= new SQLInvalidAuthorizationSpecException("Exception 3", t2);
ex.setNextException(ex1);
ex.setNextException(ex2);
int num = 0;
SQLException sqe = ex;
while (sqe != null) {
assertTrue(msgs[num++].equals(sqe.getMessage()));
Throwable c = sqe.getCause();
while (c != null) {
assertTrue(msgs[num++].equals(c.getMessage()));
c = c.getCause();
}
sqe = sqe.getNextException();
}
}
/**
* Create SQLInvalidAuthorizationSpecException and validate it is an
* instance of SQLNonTransientException
*/
@Test
public void test13() {
Exception ex = new SQLInvalidAuthorizationSpecException();
assertTrue(ex instanceof SQLNonTransientException);
}
}

View file

@ -0,0 +1,237 @@
/*
* Copyright (c) 2014, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package sql;
import java.sql.SQLException;
import java.sql.SQLNonTransientConnectionException;
import java.sql.SQLNonTransientException;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
import util.BaseTest;
public class SQLNonTransientConnectionExceptionTests extends BaseTest {
/**
* Create SQLNonTransientConnectionException and setting all objects to null
*/
@Test
public void test() {
SQLNonTransientConnectionException e =
new SQLNonTransientConnectionException(null,
null, errorCode, null);
assertTrue(e.getMessage() == null && e.getSQLState() == null
&& e.getCause() == null && e.getErrorCode() == errorCode);
}
/**
* Create SQLNonTransientConnectionException with no-arg constructor
*/
@Test
public void test1() {
SQLNonTransientConnectionException ex =
new SQLNonTransientConnectionException();
assertTrue(ex.getMessage() == null
&& ex.getSQLState() == null
&& ex.getCause() == null
&& ex.getErrorCode() == 0);
}
/**
* Create SQLNonTransientConnectionException with message
*/
@Test
public void test2() {
SQLNonTransientConnectionException ex =
new SQLNonTransientConnectionException(reason);
assertTrue(ex.getMessage().equals(reason)
&& ex.getSQLState() == null
&& ex.getCause() == null
&& ex.getErrorCode() == 0);
}
/**
* Create SQLNonTransientConnectionException with message, and SQLState
*/
@Test
public void test3() {
SQLNonTransientConnectionException ex =
new SQLNonTransientConnectionException(reason, state);
assertTrue(ex.getMessage().equals(reason)
&& ex.getSQLState().equals(state)
&& ex.getCause() == null
&& ex.getErrorCode() == 0);
}
/**
* Create SQLNonTransientConnectionException with message, SQLState, and error code
*/
@Test
public void test4() {
SQLNonTransientConnectionException ex =
new SQLNonTransientConnectionException(reason, state, errorCode);
assertTrue(ex.getMessage().equals(reason)
&& ex.getSQLState().equals(state)
&& ex.getCause() == null
&& ex.getErrorCode() == errorCode);
}
/**
* Create SQLNonTransientConnectionException with message, SQLState, errorCode, and Throwable
*/
@Test
public void test5() {
SQLNonTransientConnectionException ex =
new SQLNonTransientConnectionException(reason, state, errorCode, t);
assertTrue(ex.getMessage().equals(reason)
&& ex.getSQLState().equals(state)
&& cause.equals(ex.getCause().toString())
&& ex.getErrorCode() == errorCode);
}
/**
* Create SQLNonTransientConnectionException with message, SQLState, and Throwable
*/
@Test
public void test6() {
SQLNonTransientConnectionException ex =
new SQLNonTransientConnectionException(reason, state, t);
assertTrue(ex.getMessage().equals(reason)
&& ex.getSQLState().equals(state)
&& cause.equals(ex.getCause().toString())
&& ex.getErrorCode() == 0);
}
/**
* Create SQLNonTransientConnectionException with message, and Throwable
*/
@Test
public void test7() {
SQLNonTransientConnectionException ex =
new SQLNonTransientConnectionException(reason, t);
assertTrue(ex.getMessage().equals(reason)
&& ex.getSQLState() == null
&& cause.equals(ex.getCause().toString())
&& ex.getErrorCode() == 0);
}
/**
* Create SQLNonTransientConnectionException with null Throwable
*/
@Test
public void test8() {
SQLNonTransientConnectionException ex =
new SQLNonTransientConnectionException((Throwable)null);
assertTrue(ex.getMessage() == null
&& ex.getSQLState() == null
&& ex.getCause() == null
&& ex.getErrorCode() == 0);
}
/**
* Create SQLNonTransientConnectionException with Throwable
*/
@Test
public void test9() {
SQLNonTransientConnectionException ex =
new SQLNonTransientConnectionException(t);
assertTrue(ex.getMessage().equals(cause)
&& ex.getSQLState() == null
&& cause.equals(ex.getCause().toString())
&& ex.getErrorCode() == 0);
}
/**
* Serialize a SQLNonTransientConnectionException and make sure you can
* read it back properly
*/
@Test
public void test10() throws Exception {
SQLNonTransientConnectionException e =
new SQLNonTransientConnectionException(reason, state, errorCode, t);
SQLNonTransientConnectionException ex1 =
createSerializedException(e);
assertTrue(reason.equals(ex1.getMessage())
&& ex1.getSQLState().equals(state)
&& cause.equals(ex1.getCause().toString())
&& ex1.getErrorCode() == errorCode);
}
/**
* Validate that the ordering of the returned Exceptions is correct
* using for-each loop
*/
@Test
public void test11() {
SQLNonTransientConnectionException ex =
new SQLNonTransientConnectionException("Exception 1", t1);
SQLNonTransientConnectionException ex1 =
new SQLNonTransientConnectionException("Exception 2");
SQLNonTransientConnectionException ex2 =
new SQLNonTransientConnectionException("Exception 3", t2);
ex.setNextException(ex1);
ex.setNextException(ex2);
int num = 0;
for (Throwable e : ex) {
assertTrue(msgs[num++].equals(e.getMessage()));
}
}
/**
* Validate that the ordering of the returned Exceptions is correct
* using traditional while loop
*/
@Test
public void test12() {
SQLNonTransientConnectionException ex =
new SQLNonTransientConnectionException("Exception 1", t1);
SQLNonTransientConnectionException ex1 =
new SQLNonTransientConnectionException("Exception 2");
SQLNonTransientConnectionException ex2 =
new SQLNonTransientConnectionException("Exception 3", t2);
ex.setNextException(ex1);
ex.setNextException(ex2);
int num = 0;
SQLException sqe = ex;
while (sqe != null) {
assertTrue(msgs[num++].equals(sqe.getMessage()));
Throwable c = sqe.getCause();
while (c != null) {
assertTrue(msgs[num++].equals(c.getMessage()));
c = c.getCause();
}
sqe = sqe.getNextException();
}
}
/**
* Create SQLNonTransientConnectionException and validate it is an instance of
* SQLNonTransientException
*/
@Test
public void test13() {
Exception ex = new SQLNonTransientConnectionException();
assertTrue(ex instanceof SQLNonTransientException);
}
}

View file

@ -0,0 +1,211 @@
/*
* Copyright (c) 2014, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package sql;
import java.sql.SQLException;
import java.sql.SQLNonTransientException;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
import util.BaseTest;
public class SQLNonTransientExceptionTests extends BaseTest {
/**
* Create SQLNonTransientException and setting all objects to null
*/
@Test
public void test() {
SQLNonTransientException e = new SQLNonTransientException(null,
null, errorCode, null);
assertTrue(e.getMessage() == null && e.getSQLState() == null
&& e.getCause() == null && e.getErrorCode() == errorCode);
}
/**
* Create SQLNonTransientException with no-arg constructor
*/
@Test
public void test1() {
SQLNonTransientException ex = new SQLNonTransientException();
assertTrue(ex.getMessage() == null
&& ex.getSQLState() == null
&& ex.getCause() == null
&& ex.getErrorCode() == 0);
}
/**
* Create SQLNonTransientException with message
*/
@Test
public void test2() {
SQLNonTransientException ex = new SQLNonTransientException(reason);
assertTrue(ex.getMessage().equals(reason)
&& ex.getSQLState() == null
&& ex.getCause() == null
&& ex.getErrorCode() == 0);
}
/**
* Create SQLNonTransientException with message, and SQLState
*/
@Test
public void test3() {
SQLNonTransientException ex = new SQLNonTransientException(reason, state);
assertTrue(ex.getMessage().equals(reason)
&& ex.getSQLState().equals(state)
&& ex.getCause() == null
&& ex.getErrorCode() == 0);
}
/**
* Create SQLNonTransientException with message, SQLState, and error code
*/
@Test
public void test4() {;
SQLNonTransientException ex =
new SQLNonTransientException(reason, state, errorCode);
assertTrue(ex.getMessage().equals(reason)
&& ex.getSQLState().equals(state)
&& ex.getCause() == null
&& ex.getErrorCode() == errorCode);
}
/**
* Create SQLNonTransientException with message, SQLState, errorCode, and Throwable
*/
@Test
public void test5() {
SQLNonTransientException ex =
new SQLNonTransientException(reason, state, errorCode, t);
assertTrue(ex.getMessage().equals(reason)
&& ex.getSQLState().equals(state)
&& cause.equals(ex.getCause().toString())
&& ex.getErrorCode() == errorCode);
}
/**
* Create SQLNonTransientException with message, SQLState, and Throwable
*/
@Test
public void test6() {
SQLNonTransientException ex = new SQLNonTransientException(reason, state, t);
assertTrue(ex.getMessage().equals(reason)
&& ex.getSQLState().equals(state)
&& cause.equals(ex.getCause().toString())
&& ex.getErrorCode() == 0);
}
/**
* Create SQLNonTransientException with message, and Throwable
*/
@Test
public void test7() {
SQLNonTransientException ex = new SQLNonTransientException(reason, t);
assertTrue(ex.getMessage().equals(reason)
&& ex.getSQLState() == null
&& cause.equals(ex.getCause().toString())
&& ex.getErrorCode() == 0);
}
/**
* Create SQLNonTransientException with null Throwable
*/
@Test
public void test8() {
SQLNonTransientException ex = new SQLNonTransientException((Throwable)null);
assertTrue(ex.getMessage() == null
&& ex.getSQLState() == null
&& ex.getCause() == null
&& ex.getErrorCode() == 0);
}
/**
* Create SQLNonTransientException with Throwable
*/
@Test
public void test9() {
SQLNonTransientException ex = new SQLNonTransientException(t);
assertTrue(ex.getMessage().equals(cause)
&& ex.getSQLState() == null
&& cause.equals(ex.getCause().toString())
&& ex.getErrorCode() == 0);
}
/**
* Serialize a SQLNonTransientException and make sure you can read it back properly
*/
@Test
public void test10() throws Exception {
SQLNonTransientException e =
new SQLNonTransientException(reason, state, errorCode, t);
SQLNonTransientException ex1 =
createSerializedException(e);
assertTrue(reason.equals(ex1.getMessage())
&& ex1.getSQLState().equals(state)
&& cause.equals(ex1.getCause().toString())
&& ex1.getErrorCode() == errorCode);
}
/**
* Validate that the ordering of the returned Exceptions is correct
* using for-each loop
*/
@Test
public void test11() {
SQLNonTransientException ex = new SQLNonTransientException("Exception 1", t1);
SQLNonTransientException ex1 = new SQLNonTransientException("Exception 2");
SQLNonTransientException ex2 = new SQLNonTransientException("Exception 3", t2);
ex.setNextException(ex1);
ex.setNextException(ex2);
int num = 0;
for (Throwable e : ex) {
assertTrue(msgs[num++].equals(e.getMessage()));
}
}
/**
* Validate that the ordering of the returned Exceptions is correct
* using traditional while loop
*/
@Test
public void test12() {
SQLNonTransientException ex = new SQLNonTransientException("Exception 1", t1);
SQLNonTransientException ex1 = new SQLNonTransientException("Exception 2");
SQLNonTransientException ex2 = new SQLNonTransientException("Exception 3", t2);
ex.setNextException(ex1);
ex.setNextException(ex2);
int num = 0;
SQLException sqe = ex;
while (sqe != null) {
assertTrue(msgs[num++].equals(sqe.getMessage()));
Throwable c = sqe.getCause();
while (c != null) {
assertTrue(msgs[num++].equals(c.getMessage()));
c = c.getCause();
}
sqe = sqe.getNextException();
}
}
}

View file

@ -0,0 +1,211 @@
/*
* Copyright (c) 2014, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package sql;
import java.sql.SQLException;
import java.sql.SQLRecoverableException;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
import util.BaseTest;
public class SQLRecoverableExceptionTests extends BaseTest {
/**
* Create SQLRecoverableException and setting all objects to null
*/
@Test
public void test() {
SQLRecoverableException e = new SQLRecoverableException(null,
null, errorCode, null);
assertTrue(e.getMessage() == null && e.getSQLState() == null
&& e.getCause() == null && e.getErrorCode() == errorCode);
}
/**
* Create SQLRecoverableException with no-arg constructor
*/
@Test
public void test1() {
SQLRecoverableException ex = new SQLRecoverableException();
assertTrue(ex.getMessage() == null
&& ex.getSQLState() == null
&& ex.getCause() == null
&& ex.getErrorCode() == 0);
}
/**
* Create SQLRecoverableException with message
*/
@Test
public void test2() {
SQLRecoverableException ex = new SQLRecoverableException(reason);
assertTrue(ex.getMessage().equals(reason)
&& ex.getSQLState() == null
&& ex.getCause() == null
&& ex.getErrorCode() == 0);
}
/**
* Create SQLRecoverableException with message, and SQLState
*/
@Test
public void test3() {
SQLRecoverableException ex = new SQLRecoverableException(reason, state);
assertTrue(ex.getMessage().equals(reason)
&& ex.getSQLState().equals(state)
&& ex.getCause() == null
&& ex.getErrorCode() == 0);
}
/**
* Create SQLRecoverableException with message, SQLState, and error code
*/
@Test
public void test4() {
SQLRecoverableException ex =
new SQLRecoverableException(reason, state, errorCode);
assertTrue(ex.getMessage().equals(reason)
&& ex.getSQLState().equals(state)
&& ex.getCause() == null
&& ex.getErrorCode() == errorCode);
}
/**
* Create SQLRecoverableException with message, SQLState, errorCode, and Throwable
*/
@Test
public void test5() {
SQLRecoverableException ex =
new SQLRecoverableException(reason, state, errorCode, t);
assertTrue(ex.getMessage().equals(reason)
&& ex.getSQLState().equals(state)
&& cause.equals(ex.getCause().toString())
&& ex.getErrorCode() == errorCode);
}
/**
* Create SQLRecoverableException with message, SQLState, and Throwable
*/
@Test
public void test6() {
SQLRecoverableException ex = new SQLRecoverableException(reason, state, t);
assertTrue(ex.getMessage().equals(reason)
&& ex.getSQLState().equals(state)
&& cause.equals(ex.getCause().toString())
&& ex.getErrorCode() == 0);
}
/**
* Create SQLRecoverableException with message, and Throwable
*/
@Test
public void test7() {
SQLRecoverableException ex = new SQLRecoverableException(reason, t);
assertTrue(ex.getMessage().equals(reason)
&& ex.getSQLState() == null
&& cause.equals(ex.getCause().toString())
&& ex.getErrorCode() == 0);
}
/**
* Create SQLRecoverableException with null Throwable
*/
@Test
public void test8() {
SQLRecoverableException ex = new SQLRecoverableException((Throwable)null);
assertTrue(ex.getMessage() == null
&& ex.getSQLState() == null
&& ex.getCause() == null
&& ex.getErrorCode() == 0);
}
/**
* Create SQLRecoverableException with Throwable
*/
@Test
public void test9() {
SQLRecoverableException ex = new SQLRecoverableException(t);
assertTrue(ex.getMessage().equals(cause)
&& ex.getSQLState() == null
&& cause.equals(ex.getCause().toString())
&& ex.getErrorCode() == 0);
}
/**
* Serialize a SQLRecoverableException and make sure you can read it back properly
*/
@Test
public void test10() throws Exception {
SQLRecoverableException e =
new SQLRecoverableException(reason, state, errorCode, t);
SQLRecoverableException ex1 =
createSerializedException(e);
assertTrue(reason.equals(ex1.getMessage())
&& ex1.getSQLState().equals(state)
&& cause.equals(ex1.getCause().toString())
&& ex1.getErrorCode() == errorCode);
}
/**
* Validate that the ordering of the returned Exceptions is correct
* using for-each loop
*/
@Test
public void test11() {
SQLRecoverableException ex = new SQLRecoverableException("Exception 1", t1);
SQLRecoverableException ex1 = new SQLRecoverableException("Exception 2");
SQLRecoverableException ex2 = new SQLRecoverableException("Exception 3", t2);
ex.setNextException(ex1);
ex.setNextException(ex2);
int num = 0;
for (Throwable e : ex) {
assertTrue(msgs[num++].equals(e.getMessage()));
}
}
/**
* Validate that the ordering of the returned Exceptions is correct
* using traditional while loop
*/
@Test
public void test12() {
SQLRecoverableException ex = new SQLRecoverableException("Exception 1", t1);
SQLRecoverableException ex1 = new SQLRecoverableException("Exception 2");
SQLRecoverableException ex2 = new SQLRecoverableException("Exception 3", t2);
ex.setNextException(ex1);
ex.setNextException(ex2);
int num = 0;
SQLException sqe = ex;
while (sqe != null) {
assertTrue(msgs[num++].equals(sqe.getMessage()));
Throwable c = sqe.getCause();
while (c != null) {
assertTrue(msgs[num++].equals(c.getMessage()));
c = c.getCause();
}
sqe = sqe.getNextException();
}
}
}

View file

@ -0,0 +1,223 @@
/*
* Copyright (c) 2014, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package sql;
import java.sql.SQLException;
import java.sql.SQLNonTransientException;
import java.sql.SQLSyntaxErrorException;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
import util.BaseTest;
public class SQLSyntaxErrorExceptionTests extends BaseTest {
/**
* Create SQLSyntaxErrorException and setting all objects to null
*/
@Test
public void test() {
SQLSyntaxErrorException e = new SQLSyntaxErrorException(null,
null, errorCode, null);
assertTrue(e.getMessage() == null && e.getSQLState() == null
&& e.getCause() == null && e.getErrorCode() == errorCode);
}
/**
* Create SQLSyntaxErrorException with no-arg constructor
*/
@Test
public void test1() {
SQLSyntaxErrorException ex = new SQLSyntaxErrorException();
assertTrue(ex.getMessage() == null
&& ex.getSQLState() == null
&& ex.getCause() == null
&& ex.getErrorCode() == 0);
}
/**
* Create SQLSyntaxErrorException with message
*/
@Test
public void test2() {
SQLSyntaxErrorException ex = new SQLSyntaxErrorException(reason);
assertTrue(ex.getMessage().equals(reason)
&& ex.getSQLState() == null
&& ex.getCause() == null
&& ex.getErrorCode() == 0);
}
/**
* Create SQLSyntaxErrorException with message, and SQLState
*/
@Test
public void test3() {
SQLSyntaxErrorException ex = new SQLSyntaxErrorException(reason, state);
assertTrue(ex.getMessage().equals(reason)
&& ex.getSQLState().equals(state)
&& ex.getCause() == null
&& ex.getErrorCode() == 0);
}
/**
* Create SQLSyntaxErrorException with message, SQLState, and error code
*/
@Test
public void test4() {
SQLSyntaxErrorException ex =
new SQLSyntaxErrorException(reason, state, errorCode);
assertTrue(ex.getMessage().equals(reason)
&& ex.getSQLState().equals(state)
&& ex.getCause() == null
&& ex.getErrorCode() == errorCode);
}
/**
* Create SQLSyntaxErrorException with message, SQLState, errorCode, and Throwable
*/
@Test
public void test5() {
SQLSyntaxErrorException ex =
new SQLSyntaxErrorException(reason, state, errorCode, t);
assertTrue(ex.getMessage().equals(reason)
&& ex.getSQLState().equals(state)
&& cause.equals(ex.getCause().toString())
&& ex.getErrorCode() == errorCode);
}
/**
* Create SQLSyntaxErrorException with message, SQLState, and Throwable
*/
@Test
public void test6() {
SQLSyntaxErrorException ex = new SQLSyntaxErrorException(reason, state, t);
assertTrue(ex.getMessage().equals(reason)
&& ex.getSQLState().equals(state)
&& cause.equals(ex.getCause().toString())
&& ex.getErrorCode() == 0);
}
/**
* Create SQLSyntaxErrorException with message, and Throwable
*/
@Test
public void test7() {
SQLSyntaxErrorException ex = new SQLSyntaxErrorException(reason, t);
assertTrue(ex.getMessage().equals(reason)
&& ex.getSQLState() == null
&& cause.equals(ex.getCause().toString())
&& ex.getErrorCode() == 0);
}
/**
* Create SQLSyntaxErrorException with null Throwable
*/
@Test
public void test8() {
SQLSyntaxErrorException ex = new SQLSyntaxErrorException((Throwable)null);
assertTrue(ex.getMessage() == null
&& ex.getSQLState() == null
&& ex.getCause() == null
&& ex.getErrorCode() == 0);
}
/**
* Create SQLSyntaxErrorException with Throwable
*/
@Test
public void test9() {
SQLSyntaxErrorException ex = new SQLSyntaxErrorException(t);
assertTrue(ex.getMessage().equals(cause)
&& ex.getSQLState() == null
&& cause.equals(ex.getCause().toString())
&& ex.getErrorCode() == 0);
}
/**
* Serialize a SQLSyntaxErrorException and make sure you can read it back properly
*/
@Test
public void test10() throws Exception {
SQLSyntaxErrorException e =
new SQLSyntaxErrorException(reason, state, errorCode, t);
SQLSyntaxErrorException ex1 =
createSerializedException(e);
assertTrue(reason.equals(ex1.getMessage())
&& ex1.getSQLState().equals(state)
&& cause.equals(ex1.getCause().toString())
&& ex1.getErrorCode() == errorCode);
}
/**
* Validate that the ordering of the returned Exceptions is correct
* using for-each loop
*/
@Test
public void test11() {
SQLSyntaxErrorException ex = new SQLSyntaxErrorException("Exception 1", t1);
SQLSyntaxErrorException ex1 = new SQLSyntaxErrorException("Exception 2");
SQLSyntaxErrorException ex2 = new SQLSyntaxErrorException("Exception 3", t2);
ex.setNextException(ex1);
ex.setNextException(ex2);
int num = 0;
for (Throwable e : ex) {
assertTrue(msgs[num++].equals(e.getMessage()));
}
}
/**
* Validate that the ordering of the returned Exceptions is correct
* using traditional while loop
*/
@Test
public void test12() {
SQLSyntaxErrorException ex = new SQLSyntaxErrorException("Exception 1", t1);
SQLSyntaxErrorException ex1 = new SQLSyntaxErrorException("Exception 2");
SQLSyntaxErrorException ex2 = new SQLSyntaxErrorException("Exception 3", t2);
ex.setNextException(ex1);
ex.setNextException(ex2);
int num = 0;
SQLException sqe = ex;
while (sqe != null) {
assertTrue(msgs[num++].equals(sqe.getMessage()));
Throwable c = sqe.getCause();
while (c != null) {
assertTrue(msgs[num++].equals(c.getMessage()));
c = c.getCause();
}
sqe = sqe.getNextException();
}
}
/**
* Create SQLSyntaxErrorException and validate it is an instance of
* SQLNonTransientException
*/
@Test
public void test13() {
Exception ex = new SQLSyntaxErrorException();
assertTrue(ex instanceof SQLNonTransientException);
}
}

View file

@ -0,0 +1,220 @@
/*
* Copyright (c) 2014, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package sql;
import java.sql.SQLException;
import java.sql.SQLTimeoutException;
import java.sql.SQLTransientException;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
import util.BaseTest;
public class SQLTimeoutExceptionTests extends BaseTest {
/**
* Create SQLTimeoutException and setting all objects to null
*/
@Test
public void test() {
SQLTimeoutException e = new SQLTimeoutException(null,
null, errorCode, null);
assertTrue(e.getMessage() == null && e.getSQLState() == null
&& e.getCause() == null && e.getErrorCode() == errorCode);
}
/**
* Create SQLTimeoutException with no-arg constructor
*/
@Test
public void test1() {
SQLTimeoutException ex = new SQLTimeoutException();
assertTrue(ex.getMessage() == null
&& ex.getSQLState() == null
&& ex.getCause() == null
&& ex.getErrorCode() == 0);
}
/**
* Create SQLTimeoutException with message
*/
@Test
public void test2() {
SQLTimeoutException ex = new SQLTimeoutException(reason);
assertTrue(ex.getMessage().equals(reason)
&& ex.getSQLState() == null
&& ex.getCause() == null
&& ex.getErrorCode() == 0);
}
/**
* Create SQLTimeoutException with message, and SQLState
*/
@Test
public void test3() {
SQLTimeoutException ex = new SQLTimeoutException(reason, state);
assertTrue(ex.getMessage().equals(reason)
&& ex.getSQLState().equals(state)
&& ex.getCause() == null
&& ex.getErrorCode() == 0);
}
/**
* Create SQLTimeoutException with message, SQLState, and error code
*/
@Test
public void test4() {
SQLTimeoutException ex = new SQLTimeoutException(reason, state, errorCode);
assertTrue(ex.getMessage().equals(reason)
&& ex.getSQLState().equals(state)
&& ex.getCause() == null
&& ex.getErrorCode() == errorCode);
}
/**
* Create SQLTimeoutException with message, SQLState, errorCode, and Throwable
*/
@Test
public void test5() {
SQLTimeoutException ex = new SQLTimeoutException(reason, state, errorCode, t);
assertTrue(ex.getMessage().equals(reason)
&& ex.getSQLState().equals(state)
&& cause.equals(ex.getCause().toString())
&& ex.getErrorCode() == errorCode);
}
/**
* Create SQLTimeoutException with message, SQLState, and Throwable
*/
@Test
public void test6() {
SQLTimeoutException ex = new SQLTimeoutException(reason, state, t);
assertTrue(ex.getMessage().equals(reason)
&& ex.getSQLState().equals(state)
&& cause.equals(ex.getCause().toString())
&& ex.getErrorCode() == 0);
}
/**
* Create SQLTimeoutException with message, and Throwable
*/
@Test
public void test7() {
SQLTimeoutException ex = new SQLTimeoutException(reason, t);
assertTrue(ex.getMessage().equals(reason)
&& ex.getSQLState() == null
&& cause.equals(ex.getCause().toString())
&& ex.getErrorCode() == 0);
}
/**
* Create SQLTimeoutException with null Throwable
*/
@Test
public void test8() {
SQLTimeoutException ex = new SQLTimeoutException((Throwable)null);
assertTrue(ex.getMessage() == null
&& ex.getSQLState() == null
&& ex.getCause() == null
&& ex.getErrorCode() == 0);
}
/**
* Create SQLTimeoutException with Throwable
*/
@Test
public void test9() {
SQLTimeoutException ex = new SQLTimeoutException(t);
assertTrue(ex.getMessage().equals(cause)
&& ex.getSQLState() == null
&& cause.equals(ex.getCause().toString())
&& ex.getErrorCode() == 0);
}
/**
* Serialize a SQLTimeoutException and make sure you can read it back properly
*/
@Test
public void test10() throws Exception {
SQLTimeoutException e =
new SQLTimeoutException(reason, state, errorCode, t);
SQLTimeoutException ex1 =
createSerializedException(e);
assertTrue(reason.equals(ex1.getMessage())
&& ex1.getSQLState().equals(state)
&& cause.equals(ex1.getCause().toString())
&& ex1.getErrorCode() == errorCode);
}
/**
* Validate that the ordering of the returned Exceptions is correct
* using for-each loop
*/
@Test
public void test11() {
SQLTimeoutException ex = new SQLTimeoutException("Exception 1", t1);
SQLTimeoutException ex1 = new SQLTimeoutException("Exception 2");
SQLTimeoutException ex2 = new SQLTimeoutException("Exception 3", t2);
ex.setNextException(ex1);
ex.setNextException(ex2);
int num = 0;
for (Throwable e : ex) {
assertTrue(msgs[num++].equals(e.getMessage()));
}
}
/**
* Validate that the ordering of the returned Exceptions is correct
* using traditional while loop
*/
@Test
public void test12() {
SQLTimeoutException ex = new SQLTimeoutException("Exception 1", t1);
SQLTimeoutException ex1 = new SQLTimeoutException("Exception 2");
SQLTimeoutException ex2 = new SQLTimeoutException("Exception 3", t2);
ex.setNextException(ex1);
ex.setNextException(ex2);
int num = 0;
SQLException sqe = ex;
while (sqe != null) {
assertTrue(msgs[num++].equals(sqe.getMessage()));
Throwable c = sqe.getCause();
while (c != null) {
assertTrue(msgs[num++].equals(c.getMessage()));
c = c.getCause();
}
sqe = sqe.getNextException();
}
}
/**
* Create SQLTimeoutException and validate it is an instance of
* SQLNonTransientException
*/
@Test
public void test13() {
Exception ex = new SQLTimeoutException();
assertTrue(ex instanceof SQLTransientException);
}
}

View file

@ -0,0 +1,235 @@
/*
* Copyright (c) 2014, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package sql;
import java.sql.SQLException;
import java.sql.SQLTransactionRollbackException;
import java.sql.SQLTransientException;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
import util.BaseTest;
public class SQLTransactionRollbackExceptionTests extends BaseTest {
/**
* Create SQLTransactionRollbackException and setting all objects to null
*/
@Test
public void test() {
SQLTransactionRollbackException e =
new SQLTransactionRollbackException(null,
null, errorCode, null);
assertTrue(e.getMessage() == null && e.getSQLState() == null
&& e.getCause() == null && e.getErrorCode() == errorCode);
}
/**
* Create SQLTransactionRollbackException with no-arg constructor
*/
@Test
public void test1() {
SQLTransactionRollbackException ex = new SQLTransactionRollbackException();
assertTrue(ex.getMessage() == null
&& ex.getSQLState() == null
&& ex.getCause() == null
&& ex.getErrorCode() == 0);
}
/**
* Create SQLTransactionRollbackException with message
*/
@Test
public void test2() {
SQLTransactionRollbackException ex =
new SQLTransactionRollbackException(reason);
assertTrue(ex.getMessage().equals(reason)
&& ex.getSQLState() == null
&& ex.getCause() == null
&& ex.getErrorCode() == 0);
}
/**
* Create SQLTransactionRollbackException with message, and SQLState
*/
@Test
public void test3() {
SQLTransactionRollbackException ex =
new SQLTransactionRollbackException(reason, state);
assertTrue(ex.getMessage().equals(reason)
&& ex.getSQLState().equals(state)
&& ex.getCause() == null
&& ex.getErrorCode() == 0);
}
/**
* Create SQLTransactionRollbackException with message, SQLState, and error code
*/
@Test
public void test4() {
SQLTransactionRollbackException ex =
new SQLTransactionRollbackException(reason, state, errorCode);
assertTrue(ex.getMessage().equals(reason)
&& ex.getSQLState().equals(state)
&& ex.getCause() == null
&& ex.getErrorCode() == errorCode);
}
/**
* Create SQLTransactionRollbackException with message, SQLState, errorCode, and Throwable
*/
@Test
public void test5() {
SQLTransactionRollbackException ex =
new SQLTransactionRollbackException(reason, state, errorCode, t);
assertTrue(ex.getMessage().equals(reason)
&& ex.getSQLState().equals(state)
&& cause.equals(ex.getCause().toString())
&& ex.getErrorCode() == errorCode);
}
/**
* Create SQLTransactionRollbackException with message, SQLState, and Throwable
*/
@Test
public void test6() {
SQLTransactionRollbackException ex =
new SQLTransactionRollbackException(reason, state, t);
assertTrue(ex.getMessage().equals(reason)
&& ex.getSQLState().equals(state)
&& cause.equals(ex.getCause().toString())
&& ex.getErrorCode() == 0);
}
/**
* Create SQLTransactionRollbackException with message, and Throwable
*/
@Test
public void test7() {
SQLTransactionRollbackException ex =
new SQLTransactionRollbackException(reason, t);
assertTrue(ex.getMessage().equals(reason)
&& ex.getSQLState() == null
&& cause.equals(ex.getCause().toString())
&& ex.getErrorCode() == 0);
}
/**
* Create SQLTransactionRollbackException with null Throwable
*/
@Test
public void test8() {
SQLTransactionRollbackException ex =
new SQLTransactionRollbackException((Throwable)null);
assertTrue(ex.getMessage() == null
&& ex.getSQLState() == null
&& ex.getCause() == null
&& ex.getErrorCode() == 0);
}
/**
* Create SQLTransactionRollbackException with Throwable
*/
@Test
public void test9() {
SQLTransactionRollbackException ex =
new SQLTransactionRollbackException(t);
assertTrue(ex.getMessage().equals(cause)
&& ex.getSQLState() == null
&& cause.equals(ex.getCause().toString())
&& ex.getErrorCode() == 0);
}
/**
* Serialize a SQLTransactionRollbackException and make sure you can read it back properly
*/
@Test
public void test10() throws Exception {
SQLTransactionRollbackException e =
new SQLTransactionRollbackException(reason, state, errorCode, t);
SQLTransactionRollbackException ex1 =
createSerializedException(e);
assertTrue(reason.equals(ex1.getMessage())
&& ex1.getSQLState().equals(state)
&& cause.equals(ex1.getCause().toString())
&& ex1.getErrorCode() == errorCode);
}
/**
* Validate that the ordering of the returned Exceptions is correct
* using for-each loop
*/
@Test
public void test11() {
SQLTransactionRollbackException ex =
new SQLTransactionRollbackException("Exception 1", t1);
SQLTransactionRollbackException ex1 =
new SQLTransactionRollbackException("Exception 2");
SQLTransactionRollbackException ex2 =
new SQLTransactionRollbackException("Exception 3", t2);
ex.setNextException(ex1);
ex.setNextException(ex2);
int num = 0;
for (Throwable e : ex) {
assertTrue(msgs[num++].equals(e.getMessage()));
}
}
/**
* Validate that the ordering of the returned Exceptions is correct
* using traditional while loop
*/
@Test
public void test12() {
SQLTransactionRollbackException ex =
new SQLTransactionRollbackException("Exception 1", t1);
SQLTransactionRollbackException ex1 =
new SQLTransactionRollbackException("Exception 2");
SQLTransactionRollbackException ex2 =
new SQLTransactionRollbackException("Exception 3", t2);
ex.setNextException(ex1);
ex.setNextException(ex2);
int num = 0;
SQLException sqe = ex;
while (sqe != null) {
assertTrue(msgs[num++].equals(sqe.getMessage()));
Throwable c = sqe.getCause();
while (c != null) {
assertTrue(msgs[num++].equals(c.getMessage()));
c = c.getCause();
}
sqe = sqe.getNextException();
}
}
/**
* Create SQLTransactionRollbackException and validate it is an instance of
* SQLNonTransientException
*/
@Test
public void test13() {
Exception ex = new SQLTransactionRollbackException();
assertTrue(ex instanceof SQLTransientException);
}
}

View file

@ -0,0 +1,235 @@
/*
* Copyright (c) 2014, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package sql;
import java.sql.SQLException;
import java.sql.SQLTransientConnectionException;
import java.sql.SQLTransientException;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
import util.BaseTest;
public class SQLTransientConnectionExceptionTests extends BaseTest {
/**
* Create SQLTransientConnectionException and setting all objects to null
*/
@Test
public void test() {
SQLTransientConnectionException e =
new SQLTransientConnectionException( null,
null, errorCode, null);
assertTrue(e.getMessage() == null && e.getSQLState() == null
&& e.getCause() == null && e.getErrorCode() == errorCode);
}
/**
* Create SQLTransientConnectionException with no-arg constructor
*/
@Test
public void test1() {
SQLTransientConnectionException ex = new SQLTransientConnectionException();
assertTrue(ex.getMessage() == null
&& ex.getSQLState() == null
&& ex.getCause() == null
&& ex.getErrorCode() == 0);
}
/**
* Create SQLTransientConnectionException with message
*/
@Test
public void test2() {
SQLTransientConnectionException ex =
new SQLTransientConnectionException(reason);
assertTrue(ex.getMessage().equals(reason)
&& ex.getSQLState() == null
&& ex.getCause() == null
&& ex.getErrorCode() == 0);
}
/**
* Create SQLTransientConnectionException with message, and SQLState
*/
@Test
public void test3() {
SQLTransientConnectionException ex =
new SQLTransientConnectionException(reason, state);
assertTrue(ex.getMessage().equals(reason)
&& ex.getSQLState().equals(state)
&& ex.getCause() == null
&& ex.getErrorCode() == 0);
}
/**
* Create SQLTransientConnectionException with message, SQLState, and error code
*/
@Test
public void test4() {;
SQLTransientConnectionException ex =
new SQLTransientConnectionException(reason, state, errorCode);
assertTrue(ex.getMessage().equals(reason)
&& ex.getSQLState().equals(state)
&& ex.getCause() == null
&& ex.getErrorCode() == errorCode);
}
/**
* Create SQLTransientConnectionException with message, SQLState, errorCode, and Throwable
*/
@Test
public void test5() {
SQLTransientConnectionException ex =
new SQLTransientConnectionException(reason, state, errorCode, t);
assertTrue(ex.getMessage().equals(reason)
&& ex.getSQLState().equals(state)
&& cause.equals(ex.getCause().toString())
&& ex.getErrorCode() == errorCode);
}
/**
* Create SQLTransientConnectionException with message, SQLState, and Throwable
*/
@Test
public void test6() {
SQLTransientConnectionException ex =
new SQLTransientConnectionException(reason, state, t);
assertTrue(ex.getMessage().equals(reason)
&& ex.getSQLState().equals(state)
&& cause.equals(ex.getCause().toString())
&& ex.getErrorCode() == 0);
}
/**
* Create SQLTransientConnectionException with message, and Throwable
*/
@Test
public void test7() {
SQLTransientConnectionException ex =
new SQLTransientConnectionException(reason, t);
assertTrue(ex.getMessage().equals(reason)
&& ex.getSQLState() == null
&& cause.equals(ex.getCause().toString())
&& ex.getErrorCode() == 0);
}
/**
* Create SQLTransientConnectionException with null Throwable
*/
@Test
public void test8() {
SQLTransientConnectionException ex =
new SQLTransientConnectionException((Throwable)null);
assertTrue(ex.getMessage() == null
&& ex.getSQLState() == null
&& ex.getCause() == null
&& ex.getErrorCode() == 0);
}
/**
* Create SQLTransientConnectionException with Throwable
*/
@Test
public void test9() {
SQLTransientConnectionException ex =
new SQLTransientConnectionException(t);
assertTrue(ex.getMessage().equals(cause)
&& ex.getSQLState() == null
&& cause.equals(ex.getCause().toString())
&& ex.getErrorCode() == 0);
}
/**
* Serialize a SQLTransientConnectionException and make sure you can read it back properly
*/
@Test
public void test10() throws Exception {
SQLTransientConnectionException e =
new SQLTransientConnectionException(reason, state, errorCode, t);
SQLTransientConnectionException ex1 =
createSerializedException(e);
assertTrue(reason.equals(ex1.getMessage())
&& ex1.getSQLState().equals(state)
&& cause.equals(ex1.getCause().toString())
&& ex1.getErrorCode() == errorCode);
}
/**
* Validate that the ordering of the returned Exceptions is correct
* using for-each loop
*/
@Test
public void test11() {
SQLTransientConnectionException ex =
new SQLTransientConnectionException("Exception 1", t1);
SQLTransientConnectionException ex1 =
new SQLTransientConnectionException("Exception 2");
SQLTransientConnectionException ex2 =
new SQLTransientConnectionException("Exception 3", t2);
ex.setNextException(ex1);
ex.setNextException(ex2);
int num = 0;
for (Throwable e : ex) {
assertTrue(msgs[num++].equals(e.getMessage()));
}
}
/**
* Validate that the ordering of the returned Exceptions is correct
* using traditional while loop
*/
@Test
public void test12() {
SQLTransientConnectionException ex =
new SQLTransientConnectionException("Exception 1", t1);
SQLTransientConnectionException ex1 =
new SQLTransientConnectionException("Exception 2");
SQLTransientConnectionException ex2 =
new SQLTransientConnectionException("Exception 3", t2);
ex.setNextException(ex1);
ex.setNextException(ex2);
int num = 0;
SQLException sqe = ex;
while (sqe != null) {
assertTrue(msgs[num++].equals(sqe.getMessage()));
Throwable c = sqe.getCause();
while (c != null) {
assertTrue(msgs[num++].equals(c.getMessage()));
c = c.getCause();
}
sqe = sqe.getNextException();
}
}
/**
* Create SQLTransientConnectionException and validate it is an instance of
* SQLNonTransientException
*/
@Test
public void test13() {
Exception ex = new SQLTransientConnectionException();
assertTrue(ex instanceof SQLTransientException);
}
}

View file

@ -0,0 +1,209 @@
/*
* Copyright (c) 2014, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package sql;
import java.sql.SQLException;
import java.sql.SQLTransientException;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
import util.BaseTest;
public class SQLTransientExceptionTests extends BaseTest {
/**
* Create SQLTransientException and setting all objects to null
*/
@Test
public void test() {
SQLTransientException e = new SQLTransientException(null,
null, errorCode, null);
assertTrue(e.getMessage() == null && e.getSQLState() == null
&& e.getCause() == null && e.getErrorCode() == errorCode);
}
/**
* Create SQLTransientException with no-arg constructor
*/
@Test
public void test1() {
SQLTransientException ex = new SQLTransientException();
assertTrue(ex.getMessage() == null
&& ex.getSQLState() == null
&& ex.getCause() == null
&& ex.getErrorCode() == 0);
}
/**
* Create SQLTransientException with message
*/
@Test
public void test2() {
SQLTransientException ex = new SQLTransientException(reason);
assertTrue(ex.getMessage().equals(reason)
&& ex.getSQLState() == null
&& ex.getCause() == null
&& ex.getErrorCode() == 0);
}
/**
* Create SQLTransientException with message, and SQLState
*/
@Test
public void test3() {
SQLTransientException ex = new SQLTransientException(reason, state);
assertTrue(ex.getMessage().equals(reason)
&& ex.getSQLState().equals(state)
&& ex.getCause() == null
&& ex.getErrorCode() == 0);
}
/**
* Create SQLTransientException with message, SQLState, and error code
*/
@Test
public void test4() {
SQLTransientException ex = new SQLTransientException(reason, state, errorCode);
assertTrue(ex.getMessage().equals(reason)
&& ex.getSQLState().equals(state)
&& ex.getCause() == null
&& ex.getErrorCode() == errorCode);
}
/**
* Create SQLTransientException with message, SQLState, errorCode, and Throwable
*/
@Test
public void test5() {
SQLTransientException ex =
new SQLTransientException(reason, state, errorCode, t);
assertTrue(ex.getMessage().equals(reason)
&& ex.getSQLState().equals(state)
&& cause.equals(ex.getCause().toString())
&& ex.getErrorCode() == errorCode);
}
/**
* Create SQLTransientException with message, SQLState, and Throwable
*/
@Test
public void test6() {
SQLTransientException ex = new SQLTransientException(reason, state, t);
assertTrue(ex.getMessage().equals(reason)
&& ex.getSQLState().equals(state)
&& cause.equals(ex.getCause().toString())
&& ex.getErrorCode() == 0);
}
/**
* Create SQLTransientException with message, and Throwable
*/
@Test
public void test7() {
SQLTransientException ex = new SQLTransientException(reason, t);
assertTrue(ex.getMessage().equals(reason)
&& ex.getSQLState() == null
&& cause.equals(ex.getCause().toString())
&& ex.getErrorCode() == 0);
}
/**
* Create SQLTransientException with null Throwable
*/
@Test
public void test8() {
SQLTransientException ex = new SQLTransientException((Throwable)null);
assertTrue(ex.getMessage() == null
&& ex.getSQLState() == null
&& ex.getCause() == null
&& ex.getErrorCode() == 0);
}
/**
* Create SQLTransientException with Throwable
*/
@Test
public void test9() {
SQLTransientException ex = new SQLTransientException(t);
assertTrue(ex.getMessage().equals(cause)
&& ex.getSQLState() == null
&& cause.equals(ex.getCause().toString())
&& ex.getErrorCode() == 0);
}
/**
* Serialize a SQLTransientException and make sure you can read it back properly
*/
@Test
public void test10() throws Exception {
SQLTransientException e =
new SQLTransientException(reason, state, errorCode, t);
SQLTransientException ex1 = createSerializedException(e);
assertTrue(reason.equals(ex1.getMessage())
&& ex1.getSQLState().equals(state)
&& cause.equals(ex1.getCause().toString())
&& ex1.getErrorCode() == errorCode);
}
/**
* Validate that the ordering of the returned Exceptions is correct
* using for-each loop
*/
@Test
public void test11() {
SQLTransientException ex = new SQLTransientException("Exception 1", t1);
SQLTransientException ex1 = new SQLTransientException("Exception 2");
SQLTransientException ex2 = new SQLTransientException("Exception 3", t2);
ex.setNextException(ex1);
ex.setNextException(ex2);
int num = 0;
for (Throwable e : ex) {
assertTrue(msgs[num++].equals(e.getMessage()));
}
}
/**
* Validate that the ordering of the returned Exceptions is correct
* using traditional while loop
*/
@Test
public void test12() {
SQLTransientException ex = new SQLTransientException("Exception 1", t1);
SQLTransientException ex1 = new SQLTransientException("Exception 2");
SQLTransientException ex2 = new SQLTransientException("Exception 3", t2);
ex.setNextException(ex1);
ex.setNextException(ex2);
int num = 0;
SQLException sqe = ex;
while (sqe != null) {
assertTrue(msgs[num++].equals(sqe.getMessage()));
Throwable c = sqe.getCause();
while (c != null) {
assertTrue(msgs[num++].equals(c.getMessage()));
c = c.getCause();
}
sqe = sqe.getNextException();
}
}
}

View file

@ -0,0 +1,251 @@
/*
* Copyright (c) 2014, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package sql;
import java.sql.SQLException;
import java.sql.SQLWarning;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
import util.BaseTest;
public class SQLWarningTests extends BaseTest {
private final String[] warnings = {"Warning 1", "cause 1", "Warning 2",
"Warning 3", "cause 2"};
/**
* Create SQLWarning and setting all objects to null
*/
@Test
public void test() {
SQLWarning e = new SQLWarning(null, null, errorCode, null);
assertTrue(e.getMessage() == null && e.getSQLState() == null
&& e.getCause() == null && e.getErrorCode() == errorCode);
}
/**
* Create SQLWarning with no-arg constructor
*/
@Test
public void test1() {
SQLWarning ex = new SQLWarning();
assertTrue(ex.getMessage() == null
&& ex.getSQLState() == null
&& ex.getCause() == null
&& ex.getErrorCode() == 0);
}
/**
* Create SQLWarning with message
*/
@Test
public void test2() {
SQLWarning ex = new SQLWarning(reason);
assertTrue(ex.getMessage().equals(reason)
&& ex.getSQLState() == null
&& ex.getCause() == null
&& ex.getErrorCode() == 0);
}
/**
* Create SQLWarning with message, and SQLState
*/
@Test
public void test3() {
SQLWarning ex = new SQLWarning(reason, state);
assertTrue(ex.getMessage().equals(reason)
&& ex.getSQLState().equals(state)
&& ex.getCause() == null
&& ex.getErrorCode() == 0);
}
/**
* Create SQLWarning with message, SQLState, and error code
*/
@Test
public void test4() {
SQLWarning ex = new SQLWarning(reason, state, errorCode);
assertTrue(ex.getMessage().equals(reason)
&& ex.getSQLState().equals(state)
&& ex.getCause() == null
&& ex.getErrorCode() == errorCode);
}
/**
* Create SQLWarning with message, SQLState, errorCode, and Throwable
*/
@Test
public void test5() {
SQLWarning ex = new SQLWarning(reason, state, errorCode, t);
assertTrue(ex.getMessage().equals(reason)
&& ex.getSQLState().equals(state)
&& cause.equals(ex.getCause().toString())
&& ex.getErrorCode() == errorCode);
}
/**
* Create SQLWarning with message, SQLState, and Throwable
*/
@Test
public void test6() {
SQLWarning ex = new SQLWarning(reason, state, t);
assertTrue(ex.getMessage().equals(reason)
&& ex.getSQLState().equals(state)
&& cause.equals(ex.getCause().toString())
&& ex.getErrorCode() == 0);
}
/**
* Create SQLWarning with message, and Throwable
*/
@Test
public void test7() {
SQLWarning ex = new SQLWarning(reason, t);
assertTrue(ex.getMessage().equals(reason)
&& ex.getSQLState() == null
&& cause.equals(ex.getCause().toString())
&& ex.getErrorCode() == 0);
}
/**
* Create SQLWarning with null Throwable
*/
@Test
public void test8() {
SQLWarning ex = new SQLWarning((Throwable) null);
assertTrue(ex.getMessage() == null
&& ex.getSQLState() == null
&& ex.getCause() == null
&& ex.getErrorCode() == 0);
}
/**
* Create SQLWarning with Throwable
*/
@Test
public void test9() {
SQLWarning ex = new SQLWarning(t);
assertTrue(ex.getMessage().equals(cause)
&& ex.getSQLState() == null
&& cause.equals(ex.getCause().toString())
&& ex.getErrorCode() == 0);
}
/**
* Serialize a SQLWarning and make sure you can read it back properly
*/
@Test
public void test10() throws Exception {
SQLWarning e = new SQLWarning(reason, state, errorCode, t);
SQLWarning ex1 = createSerializedException(e);
assertTrue(reason.equals(ex1.getMessage())
&& ex1.getSQLState().equals(state)
&& cause.equals(ex1.getCause().toString())
&& ex1.getErrorCode() == errorCode);
}
/**
* Validate that the ordering of the returned Exceptions is correct using
* for-each loop
*/
@Test
public void test11() {
SQLWarning ex = new SQLWarning("Exception 1", t1);
SQLWarning ex1 = new SQLWarning("Exception 2");
SQLWarning ex2 = new SQLWarning("Exception 3", t2);
ex.setNextException(ex1);
ex.setNextException(ex2);
int num = 0;
for (Throwable e : ex) {
assertTrue(msgs[num++].equals(e.getMessage()));
}
}
/**
* Validate that the ordering of the returned Exceptions is correct using
* traditional while loop
*/
@Test
public void test12() {
SQLWarning ex = new SQLWarning("Exception 1", t1);
SQLWarning ex1 = new SQLWarning("Exception 2");
SQLWarning ex2 = new SQLWarning("Exception 3", t2);
ex.setNextException(ex1);
ex.setNextException(ex2);
int num = 0;
SQLException sqe = ex;
while (sqe != null) {
assertTrue(msgs[num++].equals(sqe.getMessage()));
Throwable c = sqe.getCause();
while (c != null) {
assertTrue(msgs[num++].equals(c.getMessage()));
c = c.getCause();
}
sqe = sqe.getNextException();
}
}
/**
* Validate that the ordering of the returned SQLWarning is correct using
* for-each loop
*/
@Test
public void test13() {
SQLWarning ex = new SQLWarning("Warning 1", t1);
SQLWarning ex1 = new SQLWarning("Warning 2");
SQLWarning ex2 = new SQLWarning("Warning 3", t2);
ex.setNextWarning(ex1);
ex.setNextWarning(ex2);
int num = 0;
for (Throwable e : ex) {
assertTrue(warnings[num++].equals(e.getMessage()));
}
}
/**
* Validate that the ordering of the returned SQLWarning is correct using
* traditional while loop
*/
@Test
public void test14() {
SQLWarning ex = new SQLWarning("Warning 1", t1);
SQLWarning ex1 = new SQLWarning("Warning 2");
SQLWarning ex2 = new SQLWarning("Warning 3", t2);
ex.setNextWarning(ex1);
ex.setNextWarning(ex2);
int num = 0;
SQLWarning sqe = ex;
while (sqe != null) {
assertTrue(warnings[num++].equals(sqe.getMessage()));
Throwable c = sqe.getCause();
while (c != null) {
assertTrue(msgs[num++].equals(c.getMessage()));
c = c.getCause();
}
sqe = sqe.getNextWarning();
}
}
}

View file

@ -0,0 +1,138 @@
/*
* Copyright (c) 2015, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package sql;
import java.sql.SQLException;
import java.sql.Statement;
import org.junit.jupiter.api.AfterEach;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.junit.jupiter.params.provider.ValueSource;
import util.BaseTest;
import util.StubConnection;
public class StatementTests extends BaseTest {
private Statement stmt;
@BeforeEach
public void setUpMethod() throws Exception {
stmt = new StubConnection().createStatement();
}
@AfterEach
public void tearDownMethod() throws Exception {
stmt.close();
}
/*
* Verify that enquoteLiteral creates a valid literal and converts every
* single quote to two single quotes
*/
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("validEnquotedLiteralValues")
public void test00(String s, String expected) throws SQLException {
assertEquals(expected, stmt.enquoteLiteral(s));
}
/*
* Validate a NullPointerException is thrown if the string passed to
* enquoteLiteral is null
*/
@Test
public void test01() throws SQLException {
assertThrows(NullPointerException.class, () -> stmt.enquoteLiteral(null));
}
/*
* Validate that enquoteIdentifier returns the expected value
*/
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("validEnquotedIdentifierValues")
public void test02(String s, boolean alwaysQuote, String expected) throws SQLException {
assertEquals(expected, stmt.enquoteIdentifier(s, alwaysQuote));
}
/*
* Validate that a SQLException is thrown for values that are not valid
* for a SQL identifier
*/
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("invalidEnquotedIdentifierValues")
public void test03(String s, boolean alwaysQuote) throws SQLException {
assertThrows(SQLException.class, () -> stmt.enquoteIdentifier(s, alwaysQuote));
}
/*
* Validate a NullPointerException is thrown is the string passed to
* enquoteIdentiifer is null
*/
@ParameterizedTest(autoCloseArguments = false)
@ValueSource(booleans = {true, false})
public void test04(boolean alwaysQuote) throws SQLException {
assertThrows(NullPointerException.class, () -> stmt.enquoteIdentifier(null, alwaysQuote));
}
/*
* Validate that isSimpleIdentifier returns the expected value
*/
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("simpleIdentifierValues")
public void test05(String s, boolean expected) throws SQLException {
assertEquals(expected, stmt.isSimpleIdentifier(s));
}
/*
* Validate a NullPointerException is thrown if the string passed to
* isSimpleIdentifier is null
*/
@Test
public void test06() throws SQLException {
assertThrows(NullPointerException.class, () -> stmt.isSimpleIdentifier(null));
}
/*
* Verify that enquoteLiteral creates a valid literal and converts every
* single quote to two single quotes
*/
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("validEnquotedNCharLiteralValues")
public void test07(String s, String expected) throws SQLException {
assertEquals(expected, stmt.enquoteNCharLiteral(s));
}
/*
* Validate a NullPointerException is thrown if the string passed to
* enquoteNCharLiteral is null
*/
@Test
public void test08() throws SQLException {
assertThrows(NullPointerException.class, () -> stmt.enquoteNCharLiteral(null));
}
}

View file

@ -0,0 +1,352 @@
/*
* Copyright (c) 2014, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package sql;
import java.sql.Time;
import java.time.LocalTime;
import java.util.stream.Stream;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import util.BaseTest;
public class TimeTests extends BaseTest {
/*
* Validate an IllegalArgumentException is thrown for calling getYear
*/
@Test
public void test01() {
Time t = Time.valueOf("08:30:59");
assertThrows(IllegalArgumentException.class, t::getYear);
}
/*
* Validate an IllegalArgumentException is thrown for calling getMonth
*/
@Test
public void test02() {
Time t = Time.valueOf("08:30:59");
assertThrows(IllegalArgumentException.class, t::getMonth);
}
/*
* Validate an IllegalArgumentException is thrown for calling getDay
*/
@Test
public void test03() {
Time t = Time.valueOf("08:30:59");
assertThrows(IllegalArgumentException.class, t::getDay);
}
/**
* Validate an IllegalArgumentException is thrown for calling getDate
*/
@Test
public void test04() {
Time t = Time.valueOf("08:30:59");
assertThrows(IllegalArgumentException.class, t::getDate);
}
/*
* Validate an IllegalArgumentException is thrown for calling setYear
*/
@Test
public void test05() {
Time t = Time.valueOf("08:30:59");
assertThrows(IllegalArgumentException.class, () -> t.setYear(8));
}
/*
* Validate an IllegalArgumentException is thrown for calling setMonth
*/
@Test
public void test06() {
Time t = Time.valueOf("08:30:59");
assertThrows(IllegalArgumentException.class, () -> t.setMonth(8));
}
/*
* Validate an IllegalArgumentException is thrown for calling setDate
*/
@Test
public void test07() {
Time t = Time.valueOf("08:30:59");
assertThrows(IllegalArgumentException.class, () -> t.setDate(30));
}
/*
* Validate an IllegalArgumentException is thrown for calling getDate
*/
@Test
public void test08() {
Time t = Time.valueOf("08:30:59");
assertThrows(IllegalArgumentException.class, t::getDate);
}
/*
* Validate that a Time made from a toLocalTime() LocalTime are equal
*/
@Test
public void test09() {
Time t = Time.valueOf("08:30:59");
Time t2 = Time.valueOf(t.toLocalTime());
assertTrue(t.equals(t2), "Error t != t2");
}
/*
* Validate that a Time LocalTime value, made from a LocalTime are equal
*/
@Test
public void test10() {
LocalTime lt = LocalTime.of(8, 30, 59);
Time t = Time.valueOf(lt);
System.out.println("lt=" + lt + ",t=" + t.toLocalTime());
assertTrue(lt.equals(t.toLocalTime()),
"Error LocalTime values are not equal");
}
/*
* Validate an NPE occurs when a null LocalDate is passed to valueOf
*/
@Test
public void test11() throws Exception {
LocalTime ld = null;
assertThrows(NullPointerException.class, () -> Time.valueOf(ld));
}
/*
* Validate an UnsupportedOperationException occurs when toInstant() is
* called
*/
@Test
public void test12() throws Exception {
Time t = new Time(System.currentTimeMillis());
assertThrows(UnsupportedOperationException.class, t::toInstant);
}
/*
* Validate that two Time objects are equal when one is created from the
* toString() of the other and that the correct value is returned from
* toString()
*/
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("validTimeValues")
public void test13(String time, String expected) {
Time t1 = Time.valueOf(time);
Time t2 = Time.valueOf(t1.toString());
assertTrue(t1.equals(t2) && t2.equals(t1)
&& t1.toString().equals(expected), "Error t1 != t2");
}
/*
* Validate that two Time values one created using valueOf and another via a
* constructor are equal
*/
@Test
public void test14() {
Time t = Time.valueOf("08:30:59");
Time t2 = new Time(8, 30, 59);
assertTrue(t.equals(t2) && t2.equals(t), "Error t != t2");
}
/*
* Validate that two Time values one created using valueOf and another via a
* constructor are equal
*/
@Test
public void test15() {
Time t = Time.valueOf("08:30:59");
Time t2 = new Time(t.getTime());
assertTrue(t.equals(t2) && t2.equals(t), "Error t != t2");
}
/*
* Validate an IllegalArgumentException is thrown for an invalid Time string
*/
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("invalidTimeValues")
public void test16(String time) throws Exception {
assertThrows(IllegalArgumentException.class, () -> Time.valueOf(time));
}
/*
* Validate that Time.after() returns false when same date is compared
*/
@Test
public void test17() {
Time t = Time.valueOf("08:30:59");
assertFalse(t.after(t), "Error t.after(t) = true");
}
/*
* Validate that Time.after() returns true when later date is compared to
* earlier date
*/
@Test
public void test18() {
Time t = Time.valueOf("08:30:59");
Time t2 = new Time(System.currentTimeMillis());
assertTrue(t2.after(t), "Error t2.after(t) = false");
}
/*
* Validate that Time.after() returns false when earlier date is compared to
* itself
*/
@Test
public void test19() {
Time t = Time.valueOf("08:30:59");
Time t2 = new Time(t.getTime());
assertFalse(t.after(t2), "Error t.after(t2) = true");
assertFalse(t2.after(t), "Error t2.after(t) = true");
}
/*
* Validate that Time.before() returns false when same date is compared
*/
@Test
public void test20() {
Time t = Time.valueOf("08:30:59");
assertFalse(t.before(t), "Error t.before(t) = true");
}
/*
* Validate that Time.before() returns true when earlier date is compared to
* later date
*/
@Test
public void test21() {
Time t = Time.valueOf("08:30:59");
Time t2 = new Time(System.currentTimeMillis());
assertTrue(t.before(t2), "Error t.before(t2) = false");
}
/*
* Validate that Time.before() returns false when earlier date is compared
* to itself
*/
@Test
public void test22() {
Time t = Time.valueOf("08:30:59");
Time t2 = new Time(t.getTime());
assertFalse(t.before(t2), "Error t.after(t2) = true");
assertFalse(t2.before(t), "Error t2.after(t) = true");
}
/*
* Validate that Time.compareTo returns 0 when both Date objects are the
* same
*/
@Test
public void test23() {
Time t = Time.valueOf("08:30:59");
assertTrue(t.compareTo(t) == 0, "Error t.compareTo(t) !=0");
}
/*
* Validate thatTime.compareTo returns 0 when both Time objects are the same
*/
@Test
public void test24() {
Time t = Time.valueOf("08:30:59");
Time t2 = new Time(t.getTime());
assertTrue(t.compareTo(t2) == 0, "Error t.compareTo(t2) !=0");
}
/*
* Validate that Time.compareTo returns 1 when comparing a later Time to an
* earlier Time
*/
@Test
public void test25() {
Time t = Time.valueOf("08:30:59");
Time t2 = new Time(t.getTime() + 1);
assertTrue(t2.compareTo(t) == 1, "Error t2.compareTo(t) !=1");
}
/*
* Validate thatTime.compareTo returns 1 when comparing a later Time to an
* earlier Time
*/
@Test
public void test26() {
Time t = Time.valueOf("08:30:59");
Time t2 = new Time(t.getTime() + 1);
assertTrue(t.compareTo(t2) == -1, "Error t.compareTo(t2) != -1");
}
/*
* DataProvider used to provide Time values which are not valid and are used
* to validate that an IllegalArgumentException will be thrown from the
* valueOf method
*/
private Stream<String> invalidTimeValues() {
return Stream.of(
"2009-11-01 10:50:01",
"1961-08-30 10:50:01.1",
"1961-08-30",
"00:00:00.",
"10:50:0.1",
":00:00",
"00::00",
"00:00:",
"::",
" : : ",
"0a:00:00",
"00:bb:00",
"00:01:cc",
"08:10:Batman",
"08:10:10:10",
"08:10",
"a:b:c",
null,
"8:"
);
}
/*
* DataProvider used to provide Time values which are valid and are used
* to validate that an IllegalArgumentException will not be thrown from the
* valueOf method. It also contains the expected return value from
* toString()
*/
private Stream<Arguments> validTimeValues() {
return Stream.of(
Arguments.of("10:50:01", "10:50:01"),
Arguments.of("01:1:1", "01:01:01"),
Arguments.of("01:01:1", "01:01:01"),
Arguments.of("1:01:1", "01:01:01"),
Arguments.of("2:02:02", "02:02:02"),
Arguments.of("2:02:2", "02:02:02"),
Arguments.of("10:50:1", "10:50:01"),
Arguments.of("00:00:00", "00:00:00"),
Arguments.of("08:30:59", "08:30:59"),
Arguments.of("9:0:1", "09:00:01")
);
}
}

View file

@ -0,0 +1,844 @@
/*
* Copyright (c) 2014, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package sql;
import java.sql.Date;
import java.sql.Time;
import java.sql.Timestamp;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Calendar;
import java.util.TimeZone;
import java.util.stream.Stream;
import org.junit.jupiter.api.AfterAll;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import util.BaseTest;
public class TimestampTests extends BaseTest {
private static TimeZone defaultTimeZone = null;
/*
* Need to set and use a custom TimeZone which does not
* observe daylight savings time for this test.
*/
@BeforeAll
public static void setUpClass() throws Exception {
defaultTimeZone = TimeZone.getDefault();
TimeZone tzone = TimeZone.getTimeZone("GMT+01");
assertFalse(tzone.observesDaylightTime());
TimeZone.setDefault(tzone);
}
/*
* Conservatively reset the default time zone after test.
*/
@AfterAll
public static void tearDownClass() throws Exception {
TimeZone.setDefault(defaultTimeZone);
}
/*
* Validate an IllegalArgumentException is thrown for an invalid Timestamp
*/
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("invalidTimestampValues")
public void test(String ts) throws Exception {
assertThrows(IllegalArgumentException.class, () -> Timestamp.valueOf(ts));
}
/*
* Validate that two Timestamp are equal when the leading 0 in seconds is
* omitted
*/
@Test
public void test01() throws Exception {
String testTS = "2009-01-01 10:50:00";
String ExpectedTS = "2009-01-01 10:50:0";
Timestamp ts = Timestamp.valueOf(testTS);
Timestamp ts2 = Timestamp.valueOf(ExpectedTS);
assertEquals(ts2, ts, "Error ts1 != ts2");
}
/*
* Validate two Timestamps created from the same string are equal
*/
@Test
public void test02() throws Exception {
String testTS = "2009-01-01 10:50:0";
Timestamp ts = Timestamp.valueOf(testTS);
Timestamp ts2 = Timestamp.valueOf(testTS);
assertEquals(ts2, ts, "Error ts1 != ts2");
}
/*
* Validate that two Timestamp values one with leading 0s for month and day
* equals same string without the leading 0s.
*/
@Test
public void test03() throws Exception {
String testTS = "2009-1-1 10:50:0";
String ExpectedTS = "2009-01-01 10:50:0";
Timestamp ts = Timestamp.valueOf(testTS);
Timestamp ts2 = Timestamp.valueOf(ExpectedTS);
assertEquals(ts2, ts, "Error ts1 != ts2");
}
/*
* Validate that two Timestamp values one with leading 0s for day omitted
* are equal
*/
@Test
public void test04() throws Exception {
String testTS = "2009-01-1 10:50:0";
String ExpectedTS = "2009-01-01 10:50:0";
Timestamp ts = Timestamp.valueOf(testTS);
Timestamp ts2 = Timestamp.valueOf(ExpectedTS);
assertEquals(ts2, ts, "Error ts1 != ts2");
}
/*
* Validate that two Timestamp values one with leading 0s for month omitted
* and both with leading 0s for seconds omitted are equal
*/
@Test
public void test05() throws Exception {
String testTS = "2009-1-01 10:50:0";
String ExpectedTS = "2009-01-01 10:50:0";
Timestamp ts = Timestamp.valueOf(testTS);
Timestamp ts2 = Timestamp.valueOf(ExpectedTS);
assertEquals(ts2, ts, "Error ts1 != ts2");
}
/*
* Validate that two Timestamp values one with leading 0s for month omitted
*/
@Test
public void test06() throws Exception {
String testTS = "2005-1-01 10:20:50.00";
String ExpectedTS = "2005-01-01 10:20:50.00";
Timestamp ts = Timestamp.valueOf(testTS);
Timestamp ts2 = Timestamp.valueOf(ExpectedTS);
assertEquals(ts2, ts, "Error ts1 != ts2");
}
/*
* Validate that two Timestamp values one created using valueOf and another
* via a constructor are equal
*/
@Test
public void test07() {
Timestamp ts1 = Timestamp.valueOf("1996-12-13 14:15:25.001");
Timestamp ts2 = new Timestamp(96, 11, 13, 14, 15, 25, 1000000);
assertTrue(ts1.equals(ts2), "Error ts1 != ts2");
}
/*
* Validate that two Timestamp values one created using valueOf and another
* via a constructor are equal
*/
@Test
public void test08() {
Timestamp ts1 = Timestamp.valueOf("1996-12-13 14:15:25.001");
Timestamp ts2 = new Timestamp(ts1.getTime());
assertTrue(ts1.equals(ts2), "Error ts1 != ts2");
}
/*
* Validate that two Timestamp values one created using valueOf and another
* via a constructor are equal
*/
@Test
public void test09() {
Timestamp ts1 = Timestamp.valueOf("1996-12-13 14:15:25.0");
Timestamp ts2 = new Timestamp(96, 11, 13, 14, 15, 25, 0);
assertTrue(ts1.equals(ts2), "Error ts1 != ts2");
}
/*
* Validate that a Timestamp cannot be equal to null
*/
@Test
public void test10() {
Timestamp ts1 = Timestamp.valueOf("1961-08-30 14:15:25.745634");
Timestamp ts2 = null;
assertFalse(ts1.equals(ts2), "Error ts1 == null");
}
/*
* Validate that a Timestamp is equal to another timestamp created with the
* using the same value but not equal to a Timestamp which is one day later
*/
@Test
public void test11() {
Timestamp ts1 = Timestamp.valueOf("1996-12-10 12:26:19.12");
Timestamp ts2 = Timestamp.valueOf("1996-12-10 12:26:19.12");
Timestamp ts3 = Timestamp.valueOf("1996-12-11 12:24:19.12");
assertTrue(ts1.equals(ts2) && ts2.equals(ts1), "Error ts1 != ts2");
assertFalse(ts1.equals(ts3) && ts3.equals(ts1), "Error ts1 == ts3");
}
/*
* Validate that a Timestamp is equal to itself
*/
@Test
public void test12() {
Timestamp ts1 = Timestamp.valueOf("1996-10-15 12:26:19.12");
assertTrue(ts1.equals(ts1), "Error ts1 != ts1");
}
/*
* Validate that two Timestamps are equal when one is created from the
* toString() of the other
*/
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("validTimestampValues")
public void test13(String ts, String expectedTS) {
Timestamp ts1 = Timestamp.valueOf(ts);
Timestamp ts2 = Timestamp.valueOf(ts1.toString());
assertTrue(ts1.equals(ts2) && ts2.equals(ts1)
&& ts1.toString().equals(expectedTS), "Error ts1 != ts2");
}
// Before Tests
/*
* Validate that Timestamp ts1 is before Timestamp ts2
*/
@Test
public void test14() {
Timestamp ts1 = Timestamp.valueOf("1996-12-13 14:15:25.745634");
Timestamp ts2 = Timestamp.valueOf("1996-12-13 15:15:25.645634");
assertTrue(ts1.before(ts2), "Error ts1 not before ts2");
}
/*
* Validate that Timestamp ts1 is before Timestamp ts2
*/
@Test
public void test15() {
Timestamp ts1 = Timestamp.valueOf("1961-08-30 14:15:25");
Timestamp ts2 = Timestamp.valueOf("1999-12-13 15:15:25");
assertTrue(ts1.before(ts2), "Error ts1 not before ts2");
}
/*
* Validate that Timestamp ts1 is before Timestamp ts2
*/
@Test
public void test16() {
Timestamp ts1 = Timestamp.valueOf("1999-12-13 14:15:25.745634");
Timestamp ts2 = Timestamp.valueOf("1999-11-13 15:15:25.645634");
assertFalse(ts1.before(ts2), "Error ts1 before ts2");
}
/*
* Validate that a NullPointerException is thrown if a null is passed to
* the before method
*/
@Test
public void test17() throws Exception {
Timestamp ts1 = Timestamp.valueOf("1996-12-13 14:15:25.745634");
assertThrows(NullPointerException.class, () -> ts1.before(null));
}
/*
* Validate a Timestamp cannot be before itself
*/
@Test
public void test18() {
Timestamp ts1 = Timestamp.valueOf("1999-11-10 12:26:19.3456543");
assertFalse(ts1.before(ts1), "Error ts1 before ts1!");
}
/*
* Create 3 Timestamps and make sure the 1st is before the other two
* Timestamps which are each greater than the one before it
*/
@Test
public void test19() {
Timestamp ts1 = new Timestamp(1234560000);
Timestamp ts2 = new Timestamp(1234567000);
Timestamp ts3 = new Timestamp(1234569000);
assertTrue(ts1.before(ts2) && ts2.before(ts3) && ts1.before(ts3));
}
/*
* Validate that Timestamp ts1 is not after Timestamp ts2
*/
@Test
public void test20() {
Timestamp ts1 = Timestamp.valueOf("1999-12-13 14:15:25.745634");
Timestamp ts2 = Timestamp.valueOf("1999-12-13 15:15:25.645634");
assertFalse(ts1.after(ts2), "Error ts1 is after ts2");
}
/*
* Validate that Timestamp ts1 is after Timestamp ts2
*/
@Test
public void test21() {
Timestamp ts1 = Timestamp.valueOf("1996-12-13 14:15:25.745634");
Timestamp ts2 = Timestamp.valueOf("1996-11-13 15:15:25.645634");
assertTrue(ts1.after(ts2), "Error ts1 not after ts2");
}
/*
* Validate that a NullPointerException is thrown if a null is passed to the
* after method
*/
@Test
public void test22() throws Exception {
Timestamp ts1 = Timestamp.valueOf("1966-08-30 08:08:08");
assertThrows(NullPointerException.class, () -> ts1.after(null));
}
/*
* Validate that a Timestamp cannot be after itself
*/
@Test
public void test23() {
Timestamp ts1 = Timestamp.valueOf("1999-11-10 12:26:19.3456543");
assertFalse(ts1.after(ts1), "Error ts1 is after itself");
}
/*
* Validate that a Timestamp after() works correctly with Timestamp created
* using milliseconds
*/
@Test
public void test24() {
Timestamp ts1 = new Timestamp(1234568000);
Timestamp ts2 = new Timestamp(1234565000);
Timestamp ts3 = new Timestamp(1234562000);
assertTrue(ts1.after(ts2) && ts2.after(ts3) && ts1.after(ts3));
}
/*
* Validate compareTo returns 0 for Timestamps that are the same
*/
@Test
public void test25() {
Timestamp ts1 = Timestamp.valueOf("1966-08-30 08:08:08");
Timestamp ts2 = new Timestamp(ts1.getTime());
assertTrue(ts1.compareTo(ts2) == 0, "Error ts1 != ts2");
}
/*
* Validate compareTo returns -1 for when the 1st Timestamp is earlier than
* the 2nd Timestamp
*/
@Test
public void test26() {
Timestamp ts1 = Timestamp.valueOf("1966-08-30 08:08:08");
Timestamp ts2 = new Timestamp(ts1.getTime() + 1000);
assertTrue(ts1.compareTo(ts2) == -1, "Error ts1 not before ts2");
assertTrue(ts2.compareTo(ts1) == 1, "Error ts1 is not before ts2");
}
/*
* Validate compareTo returns 1 for when the 1st Timestamp is later than the
* 2nd Timestamp
*/
@Test
public void test27() {
Timestamp ts1 = Timestamp.valueOf("1966-08-30 08:08:08");
Timestamp ts2 = new Timestamp(ts1.getTime() - 1000);
assertTrue(ts1.compareTo(ts2) == 1, "Error ts1 not after ts2");
assertTrue(ts2.compareTo(ts1) == -1, "Error ts1 not after ts2");
}
/*
* Validate compareTo returns 0 for Timestamps that are the same
*/
@Test
public void test28() {
Timestamp ts1 = Timestamp.valueOf("1966-08-30 08:08:08");
java.util.Date ts2 = new java.util.Date(ts1.getTime());
assertTrue(ts1.compareTo(ts2) == 0, "Error ts1 != ts2");
}
/*
* Validate compareTo returns 0 for Timestamps that are the same
*/
@Test
public void test29() {
Timestamp ts1 = Timestamp.valueOf("1966-08-30 08:08:08");
java.util.Date d = new java.util.Date(ts1.getTime());
assertFalse(ts1.equals(d), "Error ts1 == d");
}
/*
* Validate compareTo returns 0 for Timestamps that are the same
*/
@Test
public void test30() {
Timestamp ts1 = Timestamp.valueOf("1966-08-30 08:08:08");
java.util.Date d = new Timestamp(ts1.getTime());
assertTrue(ts1.equals(d), "Error ts1 != d");
}
/*
* Validate equals returns false when a Date object is passed to equals
*/
@Test
public void test31() {
Timestamp ts1 = Timestamp.valueOf("1966-08-30 08:08:08");
Date d = new Date(ts1.getTime());
assertFalse(ts1.equals(d), "Error ts1 != d");
}
/*
* Validate equals returns false when a Date object is passed to equals
*/
@Test
public void test32() {
Timestamp ts1 = Timestamp.valueOf("1966-08-30 08:08:08");
java.util.Date d = new Date(ts1.getTime());
assertFalse(ts1.equals(d), "Error ts1 != d");
}
/*
* Validate equals returns false when a Time object is passed to equals
*/
@Test
public void test33() {
Timestamp ts1 = Timestamp.valueOf("1966-08-30 08:08:08");
Time t1 = new Time(ts1.getTime());
assertFalse(ts1.equals(t1), "Error ts1 == t1");
}
/*
* Validate equals returns false when a String object is passed to equals
*/
@Test
public void test34() {
Timestamp ts1 = Timestamp.valueOf("1966-08-30 08:08:08");
assertFalse(ts1.equals("1966-08-30 08:08:08"), "Error ts1 == a String");
}
/*
* Validate getTime() returns the same value from 2 timeStamps created by
*/
@Test
public void test35() {
Timestamp ts1 = Timestamp.valueOf("1966-08-30 08:08:08");
Timestamp ts2 = Timestamp.valueOf("1966-08-30 08:08:08");
assertTrue(ts2.getTime() == ts1.getTime(),
"ts1.getTime() != ts2.getTime()");
assertTrue(ts1.equals(ts2), "Error ts1 != ts2");
}
/*
* Validate getTime() returns the same value from 2 timeStamps when
* setTime() is used to specify the same value for both Timestamps
*/
@Test
public void test36() {
Timestamp ts1 = Timestamp.valueOf("1966-08-30 08:08:08");
Timestamp ts2 = Timestamp.valueOf("1961-08-30 00:00:00");
ts2.setTime(ts1.getTime());
assertTrue(ts2.getTime() == ts1.getTime(),
"ts1.getTime() != ts2.getTime()");
assertTrue(ts1.equals(ts2), "Error ts1 != ts2");
}
/*
* Validate an IllegalArgumentException is thrown for an invalid nanos value
*/
@Test
public void test38() throws Exception {
Timestamp ts1 = Timestamp.valueOf("1961-08-30 00:00:00");
assertThrows(IllegalArgumentException.class, () -> ts1.setNanos(-1));
}
/*
* Validate an IllegalArgumentException is thrown for an invalid nanos value
*/
@Test
public void test39() throws Exception {
int nanos = 999999999;
Timestamp ts1 = Timestamp.valueOf("1961-08-30 00:00:00");
assertThrows(IllegalArgumentException.class, () -> ts1.setNanos(nanos + 1));
}
/*
* Validate you can set nanos to 999999999
*/
@Test
public void test40() throws Exception {
int nanos = 999999999;
Timestamp ts1 = Timestamp.valueOf("1961-08-30 00:00:00");
ts1.setNanos(nanos);
assertTrue(ts1.getNanos() == nanos, "Error Invalid Nanos value");
}
/*
* Validate you can set nanos to 0
*/
@Test
public void test41() throws Exception {
int nanos = 0;
Timestamp ts1 = Timestamp.valueOf("1961-08-30 00:00:00");
ts1.setNanos(nanos);
assertTrue(ts1.getNanos() == nanos, "Error Invalid Nanos value");
}
/*
* Validate that a Timestamp made from a LocalDateTime are equal
*/
@Test
public void test42() throws Exception {
Timestamp ts1 = Timestamp.valueOf("1961-08-30 00:00:00");
LocalDateTime ldt = ts1.toLocalDateTime();
Timestamp ts2 = Timestamp.valueOf(ldt);
assertTrue(ts1.equals(ts2), "Error ts1 != ts2");
}
/*
* Validate that a Timestamp LocalDateTime value, made from a LocalDateTime
* are equal
*/
@Test
public void test43() throws Exception {
LocalDateTime ldt = LocalDateTime.now();
Timestamp ts2 = Timestamp.valueOf(ldt);
assertTrue(ldt.equals(ts2.toLocalDateTime()),
"Error LocalDateTime values are not equal");
}
/*
* Validate an NPE occurs when a null LocalDateTime is passed to valueOF
*/
@Test
public void test44() throws Exception {
LocalDateTime ldt = null;
assertThrows(NullPointerException.class, () -> Timestamp.valueOf(ldt));
}
/*
* Validate that a Timestamp made from a Instant are equal
*/
@Test
public void test45() throws Exception {
Timestamp ts1 = Timestamp.valueOf("1961-08-30 00:00:00");
Instant instant = ts1.toInstant();
Timestamp ts2 = Timestamp.from(instant);
assertTrue(ts1.equals(ts2), "Error ts1 != ts2");
}
/*
* Validate that a Timestamp made from a Instant are equal
*/
@Test
public void test46() throws Exception {
Instant instant = Instant.now();
Timestamp ts2 = Timestamp.from(instant);
assertTrue(instant.equals(ts2.toInstant()),
"Error Instant values do not match");
}
/*
* Validate an NPE occurs when a null instant is passed to from
*/
@Test
public void test47() throws Exception {
Instant instant = null;
assertThrows(NullPointerException.class, () -> Timestamp.from(instant));
}
// Added SQE tests
/*
* Create a Timestamp and a 2nd Timestamp that is 1 month earlier and
* validate that it is not before or after the original Timestamp
*/
@Test
public void test48() {
Calendar cal = Calendar.getInstance();
Timestamp ts1 = new Timestamp(System.currentTimeMillis());
cal.setTimeInMillis(ts1.getTime());
cal.add(Calendar.MONTH, -1);
cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));
Timestamp ts2 = new Timestamp(cal.getTimeInMillis());
assertFalse(ts1.before(ts2) || ts2.after(ts1));
}
/*
* Create two Timestamps and validate that compareTo returns 1 to indicate
* the 1st Timestamp is greater than the 2nd Timestamp
*/
@Test
public void test49() {
Calendar cal = Calendar.getInstance();
Timestamp ts1 = new Timestamp(System.currentTimeMillis());
cal.setTimeInMillis(ts1.getTime());
cal.add(Calendar.MONTH, -1);
cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));
Timestamp ts2 = new Timestamp(cal.getTimeInMillis());
assertTrue(ts1.compareTo(ts2) == 1);
}
/*
* Create two Timestamps and validate that the 1st Timestamp is not equal to
* the 2nd Timestamp but equal to itself
*/
@Test
public void test50() {
Calendar cal = Calendar.getInstance();
Timestamp ts1 = new Timestamp(System.currentTimeMillis());
cal.setTimeInMillis(ts1.getTime());
cal.add(Calendar.MONTH, -1);
cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));
Timestamp ts2 = new Timestamp(cal.getTimeInMillis());
assertTrue(!ts1.equals(ts2) && ts1.equals(ts1));
}
/*
* Validate that two Timestamps are equal when one is created from the
* toString() of the other
*/
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("validateNanos")
public void test51(String ts, int nanos) {
Timestamp ts1 = Timestamp.valueOf(ts);
Timestamp ts2 = Timestamp.valueOf(ts1.toString());
assertTrue(ts1.getNanos() == nanos && ts1.equals(ts2),
"Error with Nanos");
}
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("validTimestampLongValues")
public void test52(long value, String ts) {
Timestamp ts1 = new Timestamp(value);
assertEquals(ts, ts1.toString(), "ts1.toString() != ts");
}
@Test
public void test53() {
// The latest Instant that can be converted to a Timestamp.
Instant instant1 = Instant.ofEpochSecond(Long.MAX_VALUE / 1000, 999_999_999);
assertEquals(instant1, Timestamp.from(instant1).toInstant());
// One nanosecond more, and converting it gets an overflow.
Instant instant2 = instant1.plusNanos(1);
assertThrows(IllegalArgumentException.class, () -> Timestamp.from(instant2));
// The earliest Instant that can be converted to a Timestamp.
Instant instant3 = Instant.ofEpochSecond(Long.MIN_VALUE / 1000, 0);
assertEquals(instant3, Timestamp.from(instant3).toInstant());
// One nanosecond less, and converting it gets an overflow.
Instant instant4 = instant3.minusNanos(1);
assertThrows(IllegalArgumentException.class, () -> Timestamp.from(instant4));
// The latest possible Instant will certainly overflow.
assertThrows(IllegalArgumentException.class, () -> Timestamp.from(Instant.MAX));
// The earliest possible Instant will certainly overflow.
assertThrows(IllegalArgumentException.class, () -> Timestamp.from(Instant.MIN));
}
/*
* Validate that two Timestamp hashCode values are equal when
* the Timestamp values match, including the nanos.
*/
@Test
public void test54() {
long t = System.currentTimeMillis();
Timestamp ts1 = new Timestamp(t);
Timestamp ts2 = new Timestamp(t);
ts1.setNanos(123456789);
ts2.setNanos(123456789);
assertTrue(ts1.equals(ts1));
assertTrue(ts2.equals(ts2));
assertTrue(ts1.equals(ts2));
// As the Timestamp values, including the nanos are the same, the hashCode's
// should be equal
assertEquals(ts2.hashCode(), ts1.hashCode());
}
/*
* Validate that two Timestamp hashCode values are not equal when only
* the nanos value for the Timestamp differ.
*/
@Test
public void test55() {
long t = System.currentTimeMillis();
Timestamp ts1 = new Timestamp(t);
Timestamp ts2 = new Timestamp(t);
// Modify the nanos so that the Timestamp values differ
ts1.setNanos(123456789);
ts2.setNanos(987654321);
assertTrue(ts1.equals(ts1));
assertTrue(ts2.equals(ts2));
assertFalse(ts1.equals(ts2));
// As the nanos differ, the hashCode values should differ
assertNotEquals(ts2.hashCode(), ts1.hashCode());
}
/*
* DataProvider used to provide Timestamps which are not valid and are used
* to validate that an IllegalArgumentException will be thrown from the
* valueOf method
*/
private Stream<String> invalidTimestampValues() {
return Stream.of(
"2009-11-01-01 10:50:01",
"aaaa-11-01-01 10:50",
"aaaa-11-01 10:50",
"1961--30 00:00:00",
"--30 00:00:00",
"-- 00:00:00",
"1961-1- 00:00:00",
"2009-11-01",
"10:50:01",
"1961-a-30 00:00:00",
"1961-01-bb 00:00:00",
"1961-08-30 00:00:00.",
"1961-08-30 :00:00",
"1961-08-30 00::00",
"1961-08-30 00:00:",
"1961-08-30 ::",
"1961-08-30 0a:00:00",
"1961-08-30 00:bb:00",
"1961-08-30 00:01:cc",
"1961-08-30 00:00:00.01a",
"1961-08-30 00:00:00.a",
"1996-12-10 12:26:19.1234567890",
null
);
}
/*
* DataProvider used to provide Timestamps which are valid and are used
* to validate that an IllegalArgumentException will not be thrown from the
* valueOf method and the corect value from toString() is returned
*/
private Stream<Arguments> validTimestampValues() {
return Stream.of(
Arguments.of("1961-08-30 00:00:00", "1961-08-30 00:00:00.0"),
Arguments.of("1961-08-30 11:22:33", "1961-08-30 11:22:33.0"),
Arguments.of("1961-8-30 00:00:00", "1961-08-30 00:00:00.0"),
Arguments.of("1966-08-1 00:00:00", "1966-08-01 00:00:00.0"),
Arguments.of("1996-12-10 12:26:19.1", "1996-12-10 12:26:19.1"),
Arguments.of("1996-12-10 12:26:19.12", "1996-12-10 12:26:19.12"),
Arguments.of("1996-12-10 12:26:19.123", "1996-12-10 12:26:19.123"),
Arguments.of("1996-12-10 12:26:19.1234", "1996-12-10 12:26:19.1234"),
Arguments.of("1996-12-10 12:26:19.12345", "1996-12-10 12:26:19.12345"),
Arguments.of("1996-12-10 12:26:19.123456", "1996-12-10 12:26:19.123456"),
Arguments.of("1996-12-10 12:26:19.1234567", "1996-12-10 12:26:19.1234567"),
Arguments.of("1996-12-10 12:26:19.12345678", "1996-12-10 12:26:19.12345678"),
Arguments.of("1996-12-10 12:26:19.123456789", "1996-12-10 12:26:19.123456789"),
Arguments.of("1996-12-10 12:26:19.000000001", "1996-12-10 12:26:19.000000001"),
Arguments.of("1996-12-10 12:26:19.000000012", "1996-12-10 12:26:19.000000012"),
Arguments.of("1996-12-10 12:26:19.000000123", "1996-12-10 12:26:19.000000123"),
Arguments.of("1996-12-10 12:26:19.000001234", "1996-12-10 12:26:19.000001234"),
Arguments.of("1996-12-10 12:26:19.000012345", "1996-12-10 12:26:19.000012345"),
Arguments.of("1996-12-10 12:26:19.000123456", "1996-12-10 12:26:19.000123456"),
Arguments.of("1996-12-10 12:26:19.001234567", "1996-12-10 12:26:19.001234567"),
Arguments.of("1996-12-10 12:26:19.12345678", "1996-12-10 12:26:19.12345678"),
Arguments.of("1996-12-10 12:26:19.0", "1996-12-10 12:26:19.0"),
Arguments.of("1996-12-10 12:26:19.01230", "1996-12-10 12:26:19.0123")
);
}
private Stream<Arguments> validTimestampLongValues() {
return Stream.of(
Arguments.of(1L, "1970-01-01 01:00:00.001"),
Arguments.of(-3600*1000L - 1, "1969-12-31 23:59:59.999"),
Arguments.of(-(20000L*365*24*60*60*1000), "18018-08-28 01:00:00.0"),
Arguments.of(Timestamp.valueOf("1961-08-30 11:22:33").getTime(), "1961-08-30 11:22:33.0"),
Arguments.of(Timestamp.valueOf("1961-08-30 11:22:33.54321000").getTime(), "1961-08-30 11:22:33.543"), // nanoprecision lost
Arguments.of(new Timestamp(114, 10, 10, 10, 10, 10, 100000000).getTime(), "2014-11-10 10:10:10.1"),
Arguments.of(new Timestamp(0, 10, 10, 10, 10, 10, 100000).getTime(), "1900-11-10 10:10:10.0"), // nanoprecision lost
Arguments.of(new Date(114, 10, 10).getTime(), "2014-11-10 00:00:00.0"),
Arguments.of(new Date(0, 10, 10).getTime(), "1900-11-10 00:00:00.0"),
Arguments.of(LocalDateTime.of(1960, 10, 10, 10, 10, 10, 50000).atZone(ZoneId.of("America/Los_Angeles"))
.toInstant().toEpochMilli(), "1960-10-10 19:10:10.0"),
// millisecond timestamps wraps around at year 1, so Long.MIN_VALUE looks similar
// Long.MAX_VALUE, while actually representing 292278994 BCE
Arguments.of(Long.MIN_VALUE, "292278994-08-17 08:12:55.192"),
Arguments.of(Long.MAX_VALUE + 1, "292278994-08-17 08:12:55.192"),
Arguments.of(Long.MAX_VALUE, "292278994-08-17 08:12:55.807"),
Arguments.of(Long.MIN_VALUE - 1, "292278994-08-17 08:12:55.807"),
// wrap around point near 0001-01-01, test that we never get a negative year:
Arguments.of(-(1970L*365*24*60*60*1000), "0001-04-25 01:00:00.0"),
Arguments.of(-(1970L*365*24*60*60*1000 + 115*24*60*60*1000L), "0001-12-31 01:00:00.0"),
Arguments.of(-(1970L*365*24*60*60*1000 + 115*24*60*60*1000L - 23*60*60*1000L), "0001-01-01 00:00:00.0"),
Arguments.of(LocalDateTime.of(0, 1, 1, 10, 10, 10, 50000).atZone(ZoneId.of("America/Los_Angeles"))
.toInstant().toEpochMilli() - 2*24*60*60*1000L, "0001-01-01 19:03:08.0"), // 1 BCE
Arguments.of(LocalDateTime.of(0, 1, 1, 10, 10, 10, 50000).atZone(ZoneId.of("America/Los_Angeles"))
.toInstant().toEpochMilli() - 3*24*60*60*1000L, "0002-12-31 19:03:08.0") // 2 BCE
);
}
/*
* DataProvider used to provide Timestamp and Nanos values in order to
* validate that the correct Nanos value is generated from the specified
* Timestamp
*/
private Stream<Arguments> validateNanos() {
return Stream.of(
Arguments.of("1961-08-30 00:00:00", 0),
Arguments.of("1996-12-10 12:26:19.1", 100000000),
Arguments.of("1996-12-10 12:26:19.12", 120000000),
Arguments.of("1996-12-10 12:26:19.123", 123000000),
Arguments.of("1996-12-10 12:26:19.1234", 123400000),
Arguments.of("1996-12-10 12:26:19.12345", 123450000),
Arguments.of("1996-12-10 12:26:19.123456", 123456000),
Arguments.of("1996-12-10 12:26:19.1234567", 123456700),
Arguments.of("1996-12-10 12:26:19.12345678", 123456780),
Arguments.of("1996-12-10 12:26:19.123456789", 123456789),
Arguments.of("1996-12-10 12:26:19.000000001", 1),
Arguments.of("1996-12-10 12:26:19.000000012", 12),
Arguments.of("1996-12-10 12:26:19.000000123", 123),
Arguments.of("1996-12-10 12:26:19.000001234", 1234),
Arguments.of("1996-12-10 12:26:19.000012345", 12345),
Arguments.of("1996-12-10 12:26:19.000123456", 123456),
Arguments.of("1996-12-10 12:26:19.001234567", 1234567),
Arguments.of("1996-12-10 12:26:19.012345678", 12345678),
Arguments.of("1996-12-10 12:26:19.0", 0),
Arguments.of("1996-12-10 12:26:19.01230", 12300000)
);
}
}

View file

@ -0,0 +1,84 @@
/*
* Copyright (c) 2016, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package sql.drivermanager;
import java.io.BufferedReader;
import java.io.CharArrayReader;
import java.io.CharArrayWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Driver;
import java.sql.DriverManager;
import java.util.Enumeration;
import java.util.logging.Level;
import java.util.logging.Logger;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
public class DriverManagerInitTests {
/**
* Validate that when DriverManager loads the initial JDBC drivers, that the
* output from DriverManager.println is available by verifying that the
* String "JDBC DriverManager initialized" is found
*/
@Test
public void test() {
CharArrayWriter cw = new CharArrayWriter();
PrintWriter pw = new PrintWriter(cw);
DriverManager.setLogWriter(pw);
Enumeration<Driver> drivers = DriverManager.getDrivers();
try (BufferedReader reader = new BufferedReader(new CharArrayReader(cw.toCharArray()))) {
boolean result
= reader.lines().anyMatch(
line -> line.matches(".*JDBC DriverManager initialized.*"));
assertTrue(result);
} catch (IOException ex) {
Logger.getLogger(DriverManagerInitTests.class.getName()).log(Level.SEVERE, null, ex);
fail();
}
// Check to verify that we are not initializing a 2nd time
cw = new CharArrayWriter();
pw = new PrintWriter(cw);
DriverManager.setLogWriter(pw);
drivers = DriverManager.getDrivers();
try (BufferedReader reader = new BufferedReader(new CharArrayReader(cw.toCharArray()))) {
boolean result
= reader.lines().noneMatch(
line -> line.matches(".*JDBC DriverManager initialized.*"));
assertTrue(result);
} catch (IOException ex) {
Logger.getLogger(DriverManagerInitTests.class.getName()).log(Level.SEVERE, null, ex);
fail();
}
}
}

View file

@ -0,0 +1,126 @@
/*
* Copyright (c) 2017, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package sql.drivermanager;
import java.sql.Connection;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.SQLException;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
/*
* @test
* @build luckydogdriver/* mystubdriver/*
* @summary Tests that a JDBC Driver that is a module can be loaded
* via the service-provider loading mechanism.
*/
public class DriverManagerModuleTests {
private final String LUCKYDOGDRIVER_URL = "jdbc:tennis:myDB";
private static final String STUBDRIVERURL = "jdbc:stub:myDB";
private static final String CONNECTION_CLASS_NAME = "com.luckydogtennis.StubConnection";
/**
* Validate JDBC drivers as modules will be accessible. One driver will be
* loaded and registered via the service-provider loading mechanism. The
* other driver will need to be explictly loaded
*
* @throws Exception
*/
@Test
public void test() throws Exception {
System.out.println("\n$$$ runing Test()\n");
dumpRegisteredDrivers();
Driver d = DriverManager.getDriver(STUBDRIVERURL);
assertNotNull(d, "StubDriver should not be null");
assertTrue(isDriverRegistered(d));
Driver d2 = null;
// This driver should not be found until it is explictly loaded
try {
d2 = DriverManager.getDriver(LUCKYDOGDRIVER_URL);
} catch (SQLException e) {
// ignore expected Exception
}
assertNull(d2, "LuckyDogDriver should be null");
loadDriver();
d2 = DriverManager.getDriver(LUCKYDOGDRIVER_URL);
assertNotNull(d2, "LuckyDogDriver should not be null");
assertTrue(isDriverRegistered(d2), "Driver was NOT registered");
dumpRegisteredDrivers();
DriverManager.deregisterDriver(d2);
assertFalse(isDriverRegistered(d2), "Driver IS STILL registered");
dumpRegisteredDrivers();
}
/**
* Validate that a Connection can be obtained from a JDBC driver which is a
* module and loaded via the service-provider loading mechanism.
*
* @throws Exception
*/
@Test
public void test00() throws Exception {
System.out.println("\n$$$ runing Test00()\n");
Connection con = DriverManager.getConnection(STUBDRIVERURL);
assertNotNull(con, "Returned Connection should not be NULL");
System.out.println("con=" + con.getClass().getName());
assertTrue(con.getClass().getName().equals(CONNECTION_CLASS_NAME));
}
/**
* Utility method to see if a driver is registered
*/
private static void dumpRegisteredDrivers() {
System.out.println("\n+++ Loaded Drivers +++");
DriverManager.drivers().forEach(d -> System.out.println("\t\t### Driver:" + d));
System.out.println("++++++++++++++++++++++++");
}
/**
* Utility method to load the LuckyDogDriver
*/
private static void loadDriver() {
try {
Class.forName("luckydogtennis.LuckyDogDriver");
} catch (ClassNotFoundException ex) {
System.out.println("**** Error: luckydogtennis.LuckyDogDriver not found");
}
System.out.println("Driver Loaded");
}
/**
* Utility method to see if a driver is registered
*/
private static boolean isDriverRegistered(Driver d) {
return DriverManager.drivers().filter(driver-> driver == d).findFirst().isPresent();
}
}

View file

@ -0,0 +1,4 @@
# drivermanager tests are run in othervm
othervm.dirs = .
# Required by DriverManagerModuleTests.java
lib.dirs = /java/sql/modules

View file

@ -0,0 +1,177 @@
/*
* Copyright (c) 2014, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package util;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.sql.JDBCType;
import java.sql.SQLException;
import java.util.stream.Stream;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.params.provider.Arguments;
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class BaseTest {
protected final String reason = "reason";
protected final String state = "SQLState";
protected final String cause = "java.lang.Throwable: cause";
protected final Throwable t = new Throwable("cause");
protected final Throwable t1 = new Throwable("cause 1");
protected final Throwable t2 = new Throwable("cause 2");
protected final int errorCode = 21;
protected final String[] msgs = {"Exception 1", "cause 1", "Exception 2",
"Exception 3", "cause 2"};
private static final String MAX_LENGTH_IDENTIFIER = "a".repeat(128);
/*
* Take some form of SQLException, serialize and deserialize it
*/
@SuppressWarnings("unchecked")
protected <T extends SQLException> T
createSerializedException(T ex)
throws IOException, ClassNotFoundException {
return (T) serializeDeserializeObject(ex);
}
/*
* Utility method to serialize and deserialize an object
*/
@SuppressWarnings("unchecked")
protected <T> T serializeDeserializeObject(T o)
throws IOException, ClassNotFoundException {
T o1;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try (ObjectOutputStream oos = new ObjectOutputStream(baos)) {
oos.writeObject(o);
}
try (ObjectInputStream ois
= new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()))) {
o1 = (T) ois.readObject();
}
return o1;
}
/*
* DataProvider used to specify the standard JDBC Types
*/
protected Stream<Integer> jdbcTypes() {
return Stream.of(JDBCType.values()).map(JDBCType::getVendorTypeNumber);
}
/*
* DataProvider used to provide strings that will be used to validate
* that enquoteLiteral converts a string to a literal and every instance of
* a single quote will be converted into two single quotes in the literal.
*/
protected Stream<Arguments> validEnquotedLiteralValues() {
return Stream.of(
Arguments.of("Hello", "'Hello'"),
Arguments.of("G'Day", "'G''Day'"),
Arguments.of("'G''Day'", "'''G''''Day'''"),
Arguments.of("I'''M", "'I''''''M'"),
Arguments.of("The Dark Knight", "'The Dark Knight'")
);
}
/*
* DataProvider used to provide strings that will be used to validate
* that enqouteIdentifier returns a simple SQL Identifier or a
* quoted identifier
*/
protected Stream<Arguments> validEnquotedIdentifierValues() {
return Stream.of(
Arguments.of("b", false, "b"),
Arguments.of("b", true, "\"b\""),
Arguments.of(MAX_LENGTH_IDENTIFIER, false, MAX_LENGTH_IDENTIFIER),
Arguments.of(MAX_LENGTH_IDENTIFIER, true, "\"" + MAX_LENGTH_IDENTIFIER + "\""),
Arguments.of("Hello", false, "Hello"),
Arguments.of("Hello", true, "\"Hello\""),
Arguments.of("G'Day", false, "\"G'Day\""),
Arguments.of("G'Day", true, "\"G'Day\""),
Arguments.of("Bruce Wayne", false, "\"Bruce Wayne\""),
Arguments.of("Bruce Wayne", true, "\"Bruce Wayne\""),
Arguments.of("select", false, "\"select\""),
Arguments.of("table", true, "\"table\""),
Arguments.of("GoodDay$", false, "\"GoodDay$\""),
Arguments.of("GoodDay$", true, "\"GoodDay$\"")
);
}
/*
* DataProvider used to provide strings are invalid for enquoteIdentifier
* resulting in a SQLException being thrown
*/
protected Stream<Arguments> invalidEnquotedIdentifierValues() {
return Stream.of(
Arguments.of("Hel\"lo", false),
Arguments.of("\"Hel\"lo\"", true),
Arguments.of("Hello" + '\0', false),
Arguments.of("", false),
Arguments.of(MAX_LENGTH_IDENTIFIER + 'a', false)
);
}
/*
* DataProvider used to provide strings that will be used to validate
* that isSimpleIdentifier returns the correct value based on the
* identifier specified.
*/
protected Stream<Arguments> simpleIdentifierValues() {
return Stream.of(
Arguments.of("b", true),
Arguments.of("Hello", true),
Arguments.of("\"Gotham\"", false),
Arguments.of("G'Day", false),
Arguments.of("Bruce Wayne", false),
Arguments.of("GoodDay$", false),
Arguments.of("Dick_Grayson", true),
Arguments.of("Batmobile1966", true),
Arguments.of(MAX_LENGTH_IDENTIFIER, true),
Arguments.of(MAX_LENGTH_IDENTIFIER + 'a', false),
Arguments.of("", false),
Arguments.of("select", false)
);
}
/*
* DataProvider used to provide strings that will be used to validate
* that enquoteNCharLiteral converts a string to a National Character
* literal and every instance of
* a single quote will be converted into two single quotes in the literal.
*/
protected Stream<Arguments> validEnquotedNCharLiteralValues() {
return Stream.of(
Arguments.of("Hello", "N'Hello'"),
Arguments.of("G'Day", "N'G''Day'"),
Arguments.of("'G''Day'", "N'''G''''Day'''"),
Arguments.of("I'''M", "N'I''''''M'"),
Arguments.of("N'Hello'", "N'N''Hello'''"),
Arguments.of("The Dark Knight", "N'The Dark Knight'")
);
}
}

View file

@ -0,0 +1,43 @@
/*
* Copyright (c) 2014, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package util;
import java.sql.DriverAction;
/**
* Simple implementation of DriverAction which calls back into the Driver when
* release is called.
*/
class DriverActionImpl implements DriverAction {
public DriverActionImpl(StubDriverDA d) {
driver = d;
}
private final StubDriverDA driver;
@Override
public void deregister() {
driver.release();
}
}

View file

@ -0,0 +1,65 @@
/*
* Copyright (c) 2014, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package util;
public class SerializedBatchUpdateException {
/**
* Serialized BatchUpdateException from JDBC 4.0 with the following values
* reason = "This was the error msg"
* SQLState = "user defined sqlState"
* vendor Code = 99999
* Update Counts = {1, 2, 21}
* cause = = "java.lang.Throwable: throw 1"
*/
public static byte[] DATA = {
(byte) 0xac, (byte) 0xed, (byte) 0x0, (byte) 0x5, (byte) 0x73, (byte) 0x72, (byte) 0x0, (byte) 0x1d, (byte) 0x6a, (byte) 0x61, (byte) 0x76, (byte) 0x61, (byte) 0x2e, (byte) 0x73, (byte) 0x71, (byte) 0x6c, (byte) 0x2e, (byte) 0x42, (byte) 0x61, (byte) 0x74, (byte) 0x63, (byte) 0x68, (byte) 0x55, (byte) 0x70, (byte) 0x64, (byte) 0x61, (byte) 0x74, (byte) 0x65, (byte) 0x45, (byte) 0x78, (byte) 0x63, (byte) 0x65,
(byte) 0x70, (byte) 0x74, (byte) 0x69, (byte) 0x6f, (byte) 0x6e, (byte) 0x52, (byte) 0xf4, (byte) 0x73, (byte) 0xc0, (byte) 0xc1, (byte) 0x8b, (byte) 0xe, (byte) 0x5d, (byte) 0x3, (byte) 0x0, (byte) 0x2, (byte) 0x5b, (byte) 0x0, (byte) 0x10, (byte) 0x6c, (byte) 0x6f, (byte) 0x6e, (byte) 0x67, (byte) 0x55, (byte) 0x70, (byte) 0x64, (byte) 0x61, (byte) 0x74, (byte) 0x65, (byte) 0x43, (byte) 0x6f, (byte) 0x75,
(byte) 0x6e, (byte) 0x74, (byte) 0x73, (byte) 0x74, (byte) 0x0, (byte) 0x2, (byte) 0x5b, (byte) 0x4a, (byte) 0x5b, (byte) 0x0, (byte) 0xc, (byte) 0x75, (byte) 0x70, (byte) 0x64, (byte) 0x61, (byte) 0x74, (byte) 0x65, (byte) 0x43, (byte) 0x6f, (byte) 0x75, (byte) 0x6e, (byte) 0x74, (byte) 0x73, (byte) 0x74, (byte) 0x0, (byte) 0x2, (byte) 0x5b, (byte) 0x49, (byte) 0x78, (byte) 0x72, (byte) 0x0, (byte) 0x15,
(byte) 0x6a, (byte) 0x61, (byte) 0x76, (byte) 0x61, (byte) 0x2e, (byte) 0x73, (byte) 0x71, (byte) 0x6c, (byte) 0x2e, (byte) 0x53, (byte) 0x51, (byte) 0x4c, (byte) 0x45, (byte) 0x78, (byte) 0x63, (byte) 0x65, (byte) 0x70, (byte) 0x74, (byte) 0x69, (byte) 0x6f, (byte) 0x6e, (byte) 0x1d, (byte) 0xa1, (byte) 0xe9, (byte) 0x30, (byte) 0xdb, (byte) 0x3e, (byte) 0x75, (byte) 0xdc, (byte) 0x2, (byte) 0x0, (byte) 0x3,
(byte) 0x49, (byte) 0x0, (byte) 0xa, (byte) 0x76, (byte) 0x65, (byte) 0x6e, (byte) 0x64, (byte) 0x6f, (byte) 0x72, (byte) 0x43, (byte) 0x6f, (byte) 0x64, (byte) 0x65, (byte) 0x4c, (byte) 0x0, (byte) 0x8, (byte) 0x53, (byte) 0x51, (byte) 0x4c, (byte) 0x53, (byte) 0x74, (byte) 0x61, (byte) 0x74, (byte) 0x65, (byte) 0x74, (byte) 0x0, (byte) 0x12, (byte) 0x4c, (byte) 0x6a, (byte) 0x61, (byte) 0x76, (byte) 0x61,
(byte) 0x2f, (byte) 0x6c, (byte) 0x61, (byte) 0x6e, (byte) 0x67, (byte) 0x2f, (byte) 0x53, (byte) 0x74, (byte) 0x72, (byte) 0x69, (byte) 0x6e, (byte) 0x67, (byte) 0x3b, (byte) 0x4c, (byte) 0x0, (byte) 0x4, (byte) 0x6e, (byte) 0x65, (byte) 0x78, (byte) 0x74, (byte) 0x74, (byte) 0x0, (byte) 0x17, (byte) 0x4c, (byte) 0x6a, (byte) 0x61, (byte) 0x76, (byte) 0x61, (byte) 0x2f, (byte) 0x73, (byte) 0x71, (byte) 0x6c,
(byte) 0x2f, (byte) 0x53, (byte) 0x51, (byte) 0x4c, (byte) 0x45, (byte) 0x78, (byte) 0x63, (byte) 0x65, (byte) 0x70, (byte) 0x74, (byte) 0x69, (byte) 0x6f, (byte) 0x6e, (byte) 0x3b, (byte) 0x78, (byte) 0x72, (byte) 0x0, (byte) 0x13, (byte) 0x6a, (byte) 0x61, (byte) 0x76, (byte) 0x61, (byte) 0x2e, (byte) 0x6c, (byte) 0x61, (byte) 0x6e, (byte) 0x67, (byte) 0x2e, (byte) 0x45, (byte) 0x78, (byte) 0x63, (byte) 0x65,
(byte) 0x70, (byte) 0x74, (byte) 0x69, (byte) 0x6f, (byte) 0x6e, (byte) 0xd0, (byte) 0xfd, (byte) 0x1f, (byte) 0x3e, (byte) 0x1a, (byte) 0x3b, (byte) 0x1c, (byte) 0xc4, (byte) 0x2, (byte) 0x0, (byte) 0x0, (byte) 0x78, (byte) 0x72, (byte) 0x0, (byte) 0x13, (byte) 0x6a, (byte) 0x61, (byte) 0x76, (byte) 0x61, (byte) 0x2e, (byte) 0x6c, (byte) 0x61, (byte) 0x6e, (byte) 0x67, (byte) 0x2e, (byte) 0x54, (byte) 0x68,
(byte) 0x72, (byte) 0x6f, (byte) 0x77, (byte) 0x61, (byte) 0x62, (byte) 0x6c, (byte) 0x65, (byte) 0xd5, (byte) 0xc6, (byte) 0x35, (byte) 0x27, (byte) 0x39, (byte) 0x77, (byte) 0xb8, (byte) 0xcb, (byte) 0x3, (byte) 0x0, (byte) 0x4, (byte) 0x4c, (byte) 0x0, (byte) 0x5, (byte) 0x63, (byte) 0x61, (byte) 0x75, (byte) 0x73, (byte) 0x65, (byte) 0x74, (byte) 0x0, (byte) 0x15, (byte) 0x4c, (byte) 0x6a, (byte) 0x61,
(byte) 0x76, (byte) 0x61, (byte) 0x2f, (byte) 0x6c, (byte) 0x61, (byte) 0x6e, (byte) 0x67, (byte) 0x2f, (byte) 0x54, (byte) 0x68, (byte) 0x72, (byte) 0x6f, (byte) 0x77, (byte) 0x61, (byte) 0x62, (byte) 0x6c, (byte) 0x65, (byte) 0x3b, (byte) 0x4c, (byte) 0x0, (byte) 0xd, (byte) 0x64, (byte) 0x65, (byte) 0x74, (byte) 0x61, (byte) 0x69, (byte) 0x6c, (byte) 0x4d, (byte) 0x65, (byte) 0x73, (byte) 0x73, (byte) 0x61,
(byte) 0x67, (byte) 0x65, (byte) 0x71, (byte) 0x0, (byte) 0x7e, (byte) 0x0, (byte) 0x4, (byte) 0x5b, (byte) 0x0, (byte) 0xa, (byte) 0x73, (byte) 0x74, (byte) 0x61, (byte) 0x63, (byte) 0x6b, (byte) 0x54, (byte) 0x72, (byte) 0x61, (byte) 0x63, (byte) 0x65, (byte) 0x74, (byte) 0x0, (byte) 0x1e, (byte) 0x5b, (byte) 0x4c, (byte) 0x6a, (byte) 0x61, (byte) 0x76, (byte) 0x61, (byte) 0x2f, (byte) 0x6c, (byte) 0x61,
(byte) 0x6e, (byte) 0x67, (byte) 0x2f, (byte) 0x53, (byte) 0x74, (byte) 0x61, (byte) 0x63, (byte) 0x6b, (byte) 0x54, (byte) 0x72, (byte) 0x61, (byte) 0x63, (byte) 0x65, (byte) 0x45, (byte) 0x6c, (byte) 0x65, (byte) 0x6d, (byte) 0x65, (byte) 0x6e, (byte) 0x74, (byte) 0x3b, (byte) 0x4c, (byte) 0x0, (byte) 0x14, (byte) 0x73, (byte) 0x75, (byte) 0x70, (byte) 0x70, (byte) 0x72, (byte) 0x65, (byte) 0x73, (byte) 0x73,
(byte) 0x65, (byte) 0x64, (byte) 0x45, (byte) 0x78, (byte) 0x63, (byte) 0x65, (byte) 0x70, (byte) 0x74, (byte) 0x69, (byte) 0x6f, (byte) 0x6e, (byte) 0x73, (byte) 0x74, (byte) 0x0, (byte) 0x10, (byte) 0x4c, (byte) 0x6a, (byte) 0x61, (byte) 0x76, (byte) 0x61, (byte) 0x2f, (byte) 0x75, (byte) 0x74, (byte) 0x69, (byte) 0x6c, (byte) 0x2f, (byte) 0x4c, (byte) 0x69, (byte) 0x73, (byte) 0x74, (byte) 0x3b, (byte) 0x78,
(byte) 0x70, (byte) 0x73, (byte) 0x71, (byte) 0x0, (byte) 0x7e, (byte) 0x0, (byte) 0x7, (byte) 0x71, (byte) 0x0, (byte) 0x7e, (byte) 0x0, (byte) 0xc, (byte) 0x74, (byte) 0x0, (byte) 0x7, (byte) 0x74, (byte) 0x68, (byte) 0x72, (byte) 0x6f, (byte) 0x77, (byte) 0x20, (byte) 0x31, (byte) 0x75, (byte) 0x72, (byte) 0x0, (byte) 0x1e, (byte) 0x5b, (byte) 0x4c, (byte) 0x6a, (byte) 0x61, (byte) 0x76, (byte) 0x61,
(byte) 0x2e, (byte) 0x6c, (byte) 0x61, (byte) 0x6e, (byte) 0x67, (byte) 0x2e, (byte) 0x53, (byte) 0x74, (byte) 0x61, (byte) 0x63, (byte) 0x6b, (byte) 0x54, (byte) 0x72, (byte) 0x61, (byte) 0x63, (byte) 0x65, (byte) 0x45, (byte) 0x6c, (byte) 0x65, (byte) 0x6d, (byte) 0x65, (byte) 0x6e, (byte) 0x74, (byte) 0x3b, (byte) 0x2, (byte) 0x46, (byte) 0x2a, (byte) 0x3c, (byte) 0x3c, (byte) 0xfd, (byte) 0x22, (byte) 0x39,
(byte) 0x2, (byte) 0x0, (byte) 0x0, (byte) 0x78, (byte) 0x70, (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x2, (byte) 0x73, (byte) 0x72, (byte) 0x0, (byte) 0x1b, (byte) 0x6a, (byte) 0x61, (byte) 0x76, (byte) 0x61, (byte) 0x2e, (byte) 0x6c, (byte) 0x61, (byte) 0x6e, (byte) 0x67, (byte) 0x2e, (byte) 0x53, (byte) 0x74, (byte) 0x61, (byte) 0x63, (byte) 0x6b, (byte) 0x54, (byte) 0x72, (byte) 0x61, (byte) 0x63,
(byte) 0x65, (byte) 0x45, (byte) 0x6c, (byte) 0x65, (byte) 0x6d, (byte) 0x65, (byte) 0x6e, (byte) 0x74, (byte) 0x61, (byte) 0x9, (byte) 0xc5, (byte) 0x9a, (byte) 0x26, (byte) 0x36, (byte) 0xdd, (byte) 0x85, (byte) 0x2, (byte) 0x0, (byte) 0x4, (byte) 0x49, (byte) 0x0, (byte) 0xa, (byte) 0x6c, (byte) 0x69, (byte) 0x6e, (byte) 0x65, (byte) 0x4e, (byte) 0x75, (byte) 0x6d, (byte) 0x62, (byte) 0x65, (byte) 0x72,
(byte) 0x4c, (byte) 0x0, (byte) 0xe, (byte) 0x64, (byte) 0x65, (byte) 0x63, (byte) 0x6c, (byte) 0x61, (byte) 0x72, (byte) 0x69, (byte) 0x6e, (byte) 0x67, (byte) 0x43, (byte) 0x6c, (byte) 0x61, (byte) 0x73, (byte) 0x73, (byte) 0x71, (byte) 0x0, (byte) 0x7e, (byte) 0x0, (byte) 0x4, (byte) 0x4c, (byte) 0x0, (byte) 0x8, (byte) 0x66, (byte) 0x69, (byte) 0x6c, (byte) 0x65, (byte) 0x4e, (byte) 0x61, (byte) 0x6d,
(byte) 0x65, (byte) 0x71, (byte) 0x0, (byte) 0x7e, (byte) 0x0, (byte) 0x4, (byte) 0x4c, (byte) 0x0, (byte) 0xa, (byte) 0x6d, (byte) 0x65, (byte) 0x74, (byte) 0x68, (byte) 0x6f, (byte) 0x64, (byte) 0x4e, (byte) 0x61, (byte) 0x6d, (byte) 0x65, (byte) 0x71, (byte) 0x0, (byte) 0x7e, (byte) 0x0, (byte) 0x4, (byte) 0x78, (byte) 0x70, (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x23, (byte) 0x74, (byte) 0x0,
(byte) 0x17, (byte) 0x43, (byte) 0x72, (byte) 0x65, (byte) 0x61, (byte) 0x74, (byte) 0x65, (byte) 0x42, (byte) 0x61, (byte) 0x74, (byte) 0x63, (byte) 0x68, (byte) 0x45, (byte) 0x78, (byte) 0x63, (byte) 0x65, (byte) 0x70, (byte) 0x74, (byte) 0x69, (byte) 0x6f, (byte) 0x6e, (byte) 0x53, (byte) 0x65, (byte) 0x72, (byte) 0x74, (byte) 0x0, (byte) 0x1c, (byte) 0x43, (byte) 0x72, (byte) 0x65, (byte) 0x61, (byte) 0x74,
(byte) 0x65, (byte) 0x42, (byte) 0x61, (byte) 0x74, (byte) 0x63, (byte) 0x68, (byte) 0x45, (byte) 0x78, (byte) 0x63, (byte) 0x65, (byte) 0x70, (byte) 0x74, (byte) 0x69, (byte) 0x6f, (byte) 0x6e, (byte) 0x53, (byte) 0x65, (byte) 0x72, (byte) 0x2e, (byte) 0x6a, (byte) 0x61, (byte) 0x76, (byte) 0x61, (byte) 0x74, (byte) 0x0, (byte) 0x9, (byte) 0x77, (byte) 0x72, (byte) 0x69, (byte) 0x74, (byte) 0x65, (byte) 0x54,
(byte) 0x65, (byte) 0x73, (byte) 0x74, (byte) 0x73, (byte) 0x71, (byte) 0x0, (byte) 0x7e, (byte) 0x0, (byte) 0x10, (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x1a, (byte) 0x71, (byte) 0x0, (byte) 0x7e, (byte) 0x0, (byte) 0x12, (byte) 0x71, (byte) 0x0, (byte) 0x7e, (byte) 0x0, (byte) 0x13, (byte) 0x74, (byte) 0x0, (byte) 0x4, (byte) 0x6d, (byte) 0x61, (byte) 0x69, (byte) 0x6e, (byte) 0x70, (byte) 0x78,
(byte) 0x74, (byte) 0x0, (byte) 0x16, (byte) 0x54, (byte) 0x68, (byte) 0x69, (byte) 0x73, (byte) 0x20, (byte) 0x77, (byte) 0x61, (byte) 0x73, (byte) 0x20, (byte) 0x74, (byte) 0x68, (byte) 0x65, (byte) 0x20, (byte) 0x65, (byte) 0x72, (byte) 0x72, (byte) 0x6f, (byte) 0x72, (byte) 0x20, (byte) 0x6d, (byte) 0x73, (byte) 0x67, (byte) 0x75, (byte) 0x71, (byte) 0x0, (byte) 0x7e, (byte) 0x0, (byte) 0xe, (byte) 0x0,
(byte) 0x0, (byte) 0x0, (byte) 0x2, (byte) 0x73, (byte) 0x71, (byte) 0x0, (byte) 0x7e, (byte) 0x0, (byte) 0x10, (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x28, (byte) 0x71, (byte) 0x0, (byte) 0x7e, (byte) 0x0, (byte) 0x12, (byte) 0x71, (byte) 0x0, (byte) 0x7e, (byte) 0x0, (byte) 0x13, (byte) 0x71, (byte) 0x0, (byte) 0x7e, (byte) 0x0, (byte) 0x14, (byte) 0x73, (byte) 0x71, (byte) 0x0, (byte) 0x7e,
(byte) 0x0, (byte) 0x10, (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x1a, (byte) 0x71, (byte) 0x0, (byte) 0x7e, (byte) 0x0, (byte) 0x12, (byte) 0x71, (byte) 0x0, (byte) 0x7e, (byte) 0x0, (byte) 0x13, (byte) 0x71, (byte) 0x0, (byte) 0x7e, (byte) 0x0, (byte) 0x16, (byte) 0x70, (byte) 0x78, (byte) 0x0, (byte) 0x1, (byte) 0x86, (byte) 0x9f, (byte) 0x74, (byte) 0x0, (byte) 0x15, (byte) 0x75, (byte) 0x73,
(byte) 0x65, (byte) 0x72, (byte) 0x20, (byte) 0x64, (byte) 0x65, (byte) 0x66, (byte) 0x69, (byte) 0x6e, (byte) 0x65, (byte) 0x64, (byte) 0x20, (byte) 0x73, (byte) 0x71, (byte) 0x6c, (byte) 0x53, (byte) 0x74, (byte) 0x61, (byte) 0x74, (byte) 0x65, (byte) 0x70, (byte) 0x75, (byte) 0x72, (byte) 0x0, (byte) 0x2, (byte) 0x5b, (byte) 0x4a, (byte) 0x78, (byte) 0x20, (byte) 0x4, (byte) 0xb5, (byte) 0x12, (byte) 0xb1,
(byte) 0x75, (byte) 0x93, (byte) 0x2, (byte) 0x0, (byte) 0x0, (byte) 0x78, (byte) 0x70, (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x3, (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x1, (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x2, (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x0,
(byte) 0x0, (byte) 0x0, (byte) 0x15, (byte) 0x75, (byte) 0x72, (byte) 0x0, (byte) 0x2, (byte) 0x5b, (byte) 0x49, (byte) 0x4d, (byte) 0xba, (byte) 0x60, (byte) 0x26, (byte) 0x76, (byte) 0xea, (byte) 0xb2, (byte) 0xa5, (byte) 0x2, (byte) 0x0, (byte) 0x0, (byte) 0x78, (byte) 0x70, (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x3, (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x1, (byte) 0x0, (byte) 0x0,
(byte) 0x0, (byte) 0x2, (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x15, (byte) 0x78
};
}

View file

@ -0,0 +1,604 @@
/*
* Copyright (c) 2015, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package util;
import java.io.InputStream;
import java.io.Reader;
import java.math.BigDecimal;
import java.net.URL;
import java.sql.*;
import java.util.Calendar;
import java.util.Map;
public class StubCallableStatement extends StubPreparedStatement
implements CallableStatement{
public StubCallableStatement(StubConnection con) {
super(con);
}
@Override
public void registerOutParameter(int parameterIndex, int sqlType) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void registerOutParameter(int parameterIndex, int sqlType, int scale) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public boolean wasNull() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public String getString(int parameterIndex) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public boolean getBoolean(int parameterIndex) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public byte getByte(int parameterIndex) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public short getShort(int parameterIndex) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public int getInt(int parameterIndex) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public long getLong(int parameterIndex) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public float getFloat(int parameterIndex) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public double getDouble(int parameterIndex) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public BigDecimal getBigDecimal(int parameterIndex, int scale) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public byte[] getBytes(int parameterIndex) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Date getDate(int parameterIndex) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Time getTime(int parameterIndex) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Timestamp getTimestamp(int parameterIndex) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Object getObject(int parameterIndex) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public BigDecimal getBigDecimal(int parameterIndex) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Object getObject(int parameterIndex, Map<String, Class<?>> map) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Ref getRef(int parameterIndex) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Blob getBlob(int parameterIndex) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Clob getClob(int parameterIndex) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Array getArray(int parameterIndex) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Date getDate(int parameterIndex, Calendar cal) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Time getTime(int parameterIndex, Calendar cal) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Timestamp getTimestamp(int parameterIndex, Calendar cal) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void registerOutParameter(int parameterIndex, int sqlType, String typeName) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void registerOutParameter(String parameterName, int sqlType) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void registerOutParameter(String parameterName, int sqlType, int scale) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void registerOutParameter(String parameterName, int sqlType, String typeName) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public URL getURL(int parameterIndex) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setURL(String parameterName, URL val) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setNull(String parameterName, int sqlType) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setBoolean(String parameterName, boolean x) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setByte(String parameterName, byte x) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setShort(String parameterName, short x) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setInt(String parameterName, int x) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setLong(String parameterName, long x) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setFloat(String parameterName, float x) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setDouble(String parameterName, double x) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setBigDecimal(String parameterName, BigDecimal x) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setString(String parameterName, String x) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setBytes(String parameterName, byte[] x) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setDate(String parameterName, Date x) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setTime(String parameterName, Time x) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setTimestamp(String parameterName, Timestamp x) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setAsciiStream(String parameterName, InputStream x, int length) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setBinaryStream(String parameterName, InputStream x, int length) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setObject(String parameterName, Object x, int targetSqlType, int scale) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setObject(String parameterName, Object x, int targetSqlType) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setObject(String parameterName, Object x) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setCharacterStream(String parameterName, Reader reader, int length) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setDate(String parameterName, Date x, Calendar cal) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setTime(String parameterName, Time x, Calendar cal) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setTimestamp(String parameterName, Timestamp x, Calendar cal) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setNull(String parameterName, int sqlType, String typeName) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public String getString(String parameterName) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public boolean getBoolean(String parameterName) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public byte getByte(String parameterName) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public short getShort(String parameterName) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public int getInt(String parameterName) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public long getLong(String parameterName) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public float getFloat(String parameterName) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public double getDouble(String parameterName) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public byte[] getBytes(String parameterName) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Date getDate(String parameterName) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Time getTime(String parameterName) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Timestamp getTimestamp(String parameterName) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Object getObject(String parameterName) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public BigDecimal getBigDecimal(String parameterName) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Object getObject(String parameterName, Map<String, Class<?>> map) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Ref getRef(String parameterName) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Blob getBlob(String parameterName) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Clob getClob(String parameterName) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Array getArray(String parameterName) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Date getDate(String parameterName, Calendar cal) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Time getTime(String parameterName, Calendar cal) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Timestamp getTimestamp(String parameterName, Calendar cal) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public URL getURL(String parameterName) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public RowId getRowId(int parameterIndex) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public RowId getRowId(String parameterName) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setRowId(String parameterName, RowId x) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setNString(String parameterName, String value) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setNCharacterStream(String parameterName, Reader value, long length) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setNClob(String parameterName, NClob value) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setClob(String parameterName, Reader reader, long length) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setBlob(String parameterName, InputStream inputStream, long length) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setNClob(String parameterName, Reader reader, long length) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public NClob getNClob(int parameterIndex) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public NClob getNClob(String parameterName) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setSQLXML(String parameterName, SQLXML xmlObject) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public SQLXML getSQLXML(int parameterIndex) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public SQLXML getSQLXML(String parameterName) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public String getNString(int parameterIndex) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public String getNString(String parameterName) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Reader getNCharacterStream(int parameterIndex) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Reader getNCharacterStream(String parameterName) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Reader getCharacterStream(int parameterIndex) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Reader getCharacterStream(String parameterName) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setBlob(String parameterName, Blob x) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setClob(String parameterName, Clob x) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setAsciiStream(String parameterName, InputStream x, long length) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setBinaryStream(String parameterName, InputStream x, long length) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setCharacterStream(String parameterName, Reader reader, long length) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setAsciiStream(String parameterName, InputStream x) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setBinaryStream(String parameterName, InputStream x) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setCharacterStream(String parameterName, Reader reader) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setNCharacterStream(String parameterName, Reader value) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setClob(String parameterName, Reader reader) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setBlob(String parameterName, InputStream inputStream) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setNClob(String parameterName, Reader reader) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public <T> T getObject(int parameterIndex, Class<T> type) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public <T> T getObject(String parameterName, Class<T> type) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
}

View file

@ -0,0 +1,324 @@
/*
* Copyright (c) 2014, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package util;
import java.sql.Array;
import java.sql.Blob;
import java.sql.CallableStatement;
import java.sql.Clob;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.NClob;
import java.sql.PreparedStatement;
import java.sql.SQLClientInfoException;
import java.sql.SQLException;
import java.sql.SQLWarning;
import java.sql.SQLXML;
import java.sql.Savepoint;
import java.sql.Statement;
import java.sql.Struct;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.Executor;
public class StubConnection implements Connection {
private boolean autoCommit = false;
private boolean isclosed;
public StubConnection() {
isclosed = false;
}
@Override
public Statement createStatement() throws SQLException {
return new StubStatement(this);
}
@Override
public PreparedStatement prepareStatement(String sql) throws SQLException {
return new StubPreparedStatement(this);
}
@Override
public CallableStatement prepareCall(String sql) throws SQLException {
return new StubCallableStatement(this);
}
@Override
public String nativeSQL(String sql) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setAutoCommit(boolean autoCommit) throws SQLException {
System.out.println("**** in StubConnection.setAutoCommit");
this.autoCommit = autoCommit;
}
@Override
public boolean getAutoCommit() throws SQLException {
System.out.println("*** in StubConnection.getAutoCommit");
return autoCommit;
}
@Override
public void commit() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void rollback() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void close() throws SQLException {
isclosed = true;
}
@Override
public boolean isClosed() throws SQLException {
return isclosed;
}
@Override
public DatabaseMetaData getMetaData() throws SQLException {
return new StubDatabaseMetaData();
}
@Override
public void setReadOnly(boolean readOnly) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public boolean isReadOnly() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setCatalog(String catalog) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public String getCatalog() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setTransactionIsolation(int level) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public int getTransactionIsolation() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public SQLWarning getWarnings() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void clearWarnings() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Map<String, Class<?>> getTypeMap() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setTypeMap(Map<String, Class<?>> map) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setHoldability(int holdability) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public int getHoldability() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Savepoint setSavepoint() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Savepoint setSavepoint(String name) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void rollback(Savepoint savepoint) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void releaseSavepoint(Savepoint savepoint) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Clob createClob() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Blob createBlob() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public NClob createNClob() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public SQLXML createSQLXML() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public boolean isValid(int timeout) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setClientInfo(String name, String value) throws SQLClientInfoException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setClientInfo(Properties properties) throws SQLClientInfoException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public String getClientInfo(String name) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Properties getClientInfo() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Array createArrayOf(String typeName, Object[] elements) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Struct createStruct(String typeName, Object[] attributes) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setSchema(String schema) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public String getSchema() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void abort(Executor executor) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setNetworkTimeout(Executor executor, int milliseconds) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public int getNetworkTimeout() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public <T> T unwrap(Class<T> iface) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public boolean isWrapperFor(Class<?> iface) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
}

View file

@ -0,0 +1,907 @@
/*
* Copyright (c) 2025, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package util;
import java.sql.*;
public class StubDatabaseMetaData implements DatabaseMetaData {
@Override
public boolean allProceduresAreCallable() throws SQLException {
return false;
}
@Override
public boolean allTablesAreSelectable() throws SQLException {
return false;
}
@Override
public String getURL() throws SQLException {
return "";
}
@Override
public String getUserName() throws SQLException {
return "";
}
@Override
public boolean isReadOnly() throws SQLException {
return false;
}
@Override
public boolean nullsAreSortedHigh() throws SQLException {
return false;
}
@Override
public boolean nullsAreSortedLow() throws SQLException {
return false;
}
@Override
public boolean nullsAreSortedAtStart() throws SQLException {
return false;
}
@Override
public boolean nullsAreSortedAtEnd() throws SQLException {
return false;
}
@Override
public String getDatabaseProductName() throws SQLException {
return "";
}
@Override
public String getDatabaseProductVersion() throws SQLException {
return "";
}
@Override
public String getDriverName() throws SQLException {
return "";
}
@Override
public String getDriverVersion() throws SQLException {
return "";
}
@Override
public int getDriverMajorVersion() {
return 0;
}
@Override
public int getDriverMinorVersion() {
return 0;
}
@Override
public boolean usesLocalFiles() throws SQLException {
return false;
}
@Override
public boolean usesLocalFilePerTable() throws SQLException {
return false;
}
@Override
public boolean supportsMixedCaseIdentifiers() throws SQLException {
return false;
}
@Override
public boolean storesUpperCaseIdentifiers() throws SQLException {
return false;
}
@Override
public boolean storesLowerCaseIdentifiers() throws SQLException {
return false;
}
@Override
public boolean storesMixedCaseIdentifiers() throws SQLException {
return false;
}
@Override
public boolean supportsMixedCaseQuotedIdentifiers() throws SQLException {
return false;
}
@Override
public boolean storesUpperCaseQuotedIdentifiers() throws SQLException {
return false;
}
@Override
public boolean storesLowerCaseQuotedIdentifiers() throws SQLException {
return false;
}
@Override
public boolean storesMixedCaseQuotedIdentifiers() throws SQLException {
return false;
}
@Override
public String getIdentifierQuoteString() throws SQLException {
return "\"";
}
@Override
public String getSQLKeywords() throws SQLException {
return "";
}
@Override
public String getNumericFunctions() throws SQLException {
return "";
}
@Override
public String getStringFunctions() throws SQLException {
return "";
}
@Override
public String getSystemFunctions() throws SQLException {
return "";
}
@Override
public String getTimeDateFunctions() throws SQLException {
return "";
}
@Override
public String getSearchStringEscape() throws SQLException {
return "";
}
@Override
public String getExtraNameCharacters() throws SQLException {
return "";
}
@Override
public boolean supportsAlterTableWithAddColumn() throws SQLException {
return false;
}
@Override
public boolean supportsAlterTableWithDropColumn() throws SQLException {
return false;
}
@Override
public boolean supportsColumnAliasing() throws SQLException {
return false;
}
@Override
public boolean nullPlusNonNullIsNull() throws SQLException {
return false;
}
@Override
public boolean supportsConvert() throws SQLException {
return false;
}
@Override
public boolean supportsConvert(int fromType, int toType) throws SQLException {
return false;
}
@Override
public boolean supportsTableCorrelationNames() throws SQLException {
return false;
}
@Override
public boolean supportsDifferentTableCorrelationNames() throws SQLException {
return false;
}
@Override
public boolean supportsExpressionsInOrderBy() throws SQLException {
return false;
}
@Override
public boolean supportsOrderByUnrelated() throws SQLException {
return false;
}
@Override
public boolean supportsGroupBy() throws SQLException {
return false;
}
@Override
public boolean supportsGroupByUnrelated() throws SQLException {
return false;
}
@Override
public boolean supportsGroupByBeyondSelect() throws SQLException {
return false;
}
@Override
public boolean supportsLikeEscapeClause() throws SQLException {
return false;
}
@Override
public boolean supportsMultipleResultSets() throws SQLException {
return false;
}
@Override
public boolean supportsMultipleTransactions() throws SQLException {
return false;
}
@Override
public boolean supportsNonNullableColumns() throws SQLException {
return false;
}
@Override
public boolean supportsMinimumSQLGrammar() throws SQLException {
return false;
}
@Override
public boolean supportsCoreSQLGrammar() throws SQLException {
return false;
}
@Override
public boolean supportsExtendedSQLGrammar() throws SQLException {
return false;
}
@Override
public boolean supportsANSI92EntryLevelSQL() throws SQLException {
return false;
}
@Override
public boolean supportsANSI92IntermediateSQL() throws SQLException {
return false;
}
@Override
public boolean supportsANSI92FullSQL() throws SQLException {
return false;
}
@Override
public boolean supportsIntegrityEnhancementFacility() throws SQLException {
return false;
}
@Override
public boolean supportsOuterJoins() throws SQLException {
return false;
}
@Override
public boolean supportsFullOuterJoins() throws SQLException {
return false;
}
@Override
public boolean supportsLimitedOuterJoins() throws SQLException {
return false;
}
@Override
public String getSchemaTerm() throws SQLException {
return "";
}
@Override
public String getProcedureTerm() throws SQLException {
return "";
}
@Override
public String getCatalogTerm() throws SQLException {
return "";
}
@Override
public boolean isCatalogAtStart() throws SQLException {
return false;
}
@Override
public String getCatalogSeparator() throws SQLException {
return "";
}
@Override
public boolean supportsSchemasInDataManipulation() throws SQLException {
return false;
}
@Override
public boolean supportsSchemasInProcedureCalls() throws SQLException {
return false;
}
@Override
public boolean supportsSchemasInTableDefinitions() throws SQLException {
return false;
}
@Override
public boolean supportsSchemasInIndexDefinitions() throws SQLException {
return false;
}
@Override
public boolean supportsSchemasInPrivilegeDefinitions() throws SQLException {
return false;
}
@Override
public boolean supportsCatalogsInDataManipulation() throws SQLException {
return false;
}
@Override
public boolean supportsCatalogsInProcedureCalls() throws SQLException {
return false;
}
@Override
public boolean supportsCatalogsInTableDefinitions() throws SQLException {
return false;
}
@Override
public boolean supportsCatalogsInIndexDefinitions() throws SQLException {
return false;
}
@Override
public boolean supportsCatalogsInPrivilegeDefinitions() throws SQLException {
return false;
}
@Override
public boolean supportsPositionedDelete() throws SQLException {
return false;
}
@Override
public boolean supportsPositionedUpdate() throws SQLException {
return false;
}
@Override
public boolean supportsSelectForUpdate() throws SQLException {
return false;
}
@Override
public boolean supportsStoredProcedures() throws SQLException {
return false;
}
@Override
public boolean supportsSubqueriesInComparisons() throws SQLException {
return false;
}
@Override
public boolean supportsSubqueriesInExists() throws SQLException {
return false;
}
@Override
public boolean supportsSubqueriesInIns() throws SQLException {
return false;
}
@Override
public boolean supportsSubqueriesInQuantifieds() throws SQLException {
return false;
}
@Override
public boolean supportsCorrelatedSubqueries() throws SQLException {
return false;
}
@Override
public boolean supportsUnion() throws SQLException {
return false;
}
@Override
public boolean supportsUnionAll() throws SQLException {
return false;
}
@Override
public boolean supportsOpenCursorsAcrossCommit() throws SQLException {
return false;
}
@Override
public boolean supportsOpenCursorsAcrossRollback() throws SQLException {
return false;
}
@Override
public boolean supportsOpenStatementsAcrossCommit() throws SQLException {
return false;
}
@Override
public boolean supportsOpenStatementsAcrossRollback() throws SQLException {
return false;
}
@Override
public int getMaxBinaryLiteralLength() throws SQLException {
return 0;
}
@Override
public int getMaxCharLiteralLength() throws SQLException {
return 0;
}
@Override
public int getMaxColumnNameLength() throws SQLException {
return 0;
}
@Override
public int getMaxColumnsInGroupBy() throws SQLException {
return 0;
}
@Override
public int getMaxColumnsInIndex() throws SQLException {
return 0;
}
@Override
public int getMaxColumnsInOrderBy() throws SQLException {
return 0;
}
@Override
public int getMaxColumnsInSelect() throws SQLException {
return 0;
}
@Override
public int getMaxColumnsInTable() throws SQLException {
return 0;
}
@Override
public int getMaxConnections() throws SQLException {
return 0;
}
@Override
public int getMaxCursorNameLength() throws SQLException {
return 0;
}
@Override
public int getMaxIndexLength() throws SQLException {
return 0;
}
@Override
public int getMaxSchemaNameLength() throws SQLException {
return 0;
}
@Override
public int getMaxProcedureNameLength() throws SQLException {
return 0;
}
@Override
public int getMaxCatalogNameLength() throws SQLException {
return 0;
}
@Override
public int getMaxRowSize() throws SQLException {
return 0;
}
@Override
public boolean doesMaxRowSizeIncludeBlobs() throws SQLException {
return false;
}
@Override
public int getMaxStatementLength() throws SQLException {
return 0;
}
@Override
public int getMaxStatements() throws SQLException {
return 0;
}
@Override
public int getMaxTableNameLength() throws SQLException {
return 0;
}
@Override
public int getMaxTablesInSelect() throws SQLException {
return 0;
}
@Override
public int getMaxUserNameLength() throws SQLException {
return 0;
}
@Override
public int getDefaultTransactionIsolation() throws SQLException {
return 0;
}
@Override
public boolean supportsTransactions() throws SQLException {
return false;
}
@Override
public boolean supportsTransactionIsolationLevel(int level) throws SQLException {
return false;
}
@Override
public boolean supportsDataDefinitionAndDataManipulationTransactions() throws SQLException {
return false;
}
@Override
public boolean supportsDataManipulationTransactionsOnly() throws SQLException {
return false;
}
@Override
public boolean dataDefinitionCausesTransactionCommit() throws SQLException {
return false;
}
@Override
public boolean dataDefinitionIgnoredInTransactions() throws SQLException {
return false;
}
@Override
public ResultSet getProcedures(String catalog, String schemaPattern, String procedureNamePattern) throws SQLException {
return null;
}
@Override
public ResultSet getProcedureColumns(String catalog, String schemaPattern, String procedureNamePattern, String columnNamePattern) throws SQLException {
return null;
}
@Override
public ResultSet getTables(String catalog, String schemaPattern, String tableNamePattern, String[] types) throws SQLException {
return null;
}
@Override
public ResultSet getSchemas() throws SQLException {
return null;
}
@Override
public ResultSet getCatalogs() throws SQLException {
return null;
}
@Override
public ResultSet getTableTypes() throws SQLException {
return null;
}
@Override
public ResultSet getColumns(String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern) throws SQLException {
return null;
}
@Override
public ResultSet getColumnPrivileges(String catalog, String schema, String table, String columnNamePattern) throws SQLException {
return null;
}
@Override
public ResultSet getTablePrivileges(String catalog, String schemaPattern, String tableNamePattern) throws SQLException {
return null;
}
@Override
public ResultSet getBestRowIdentifier(String catalog, String schema, String table, int scope, boolean nullable) throws SQLException {
return null;
}
@Override
public ResultSet getVersionColumns(String catalog, String schema, String table) throws SQLException {
return null;
}
@Override
public ResultSet getPrimaryKeys(String catalog, String schema, String table) throws SQLException {
return null;
}
@Override
public ResultSet getImportedKeys(String catalog, String schema, String table) throws SQLException {
return null;
}
@Override
public ResultSet getExportedKeys(String catalog, String schema, String table) throws SQLException {
return null;
}
@Override
public ResultSet getCrossReference(String parentCatalog, String parentSchema, String parentTable, String foreignCatalog, String foreignSchema, String foreignTable) throws SQLException {
return null;
}
@Override
public ResultSet getTypeInfo() throws SQLException {
return null;
}
@Override
public ResultSet getIndexInfo(String catalog, String schema, String table, boolean unique, boolean approximate) throws SQLException {
return null;
}
@Override
public boolean supportsResultSetType(int type) throws SQLException {
return false;
}
@Override
public boolean supportsResultSetConcurrency(int type, int concurrency) throws SQLException {
return false;
}
@Override
public boolean ownUpdatesAreVisible(int type) throws SQLException {
return false;
}
@Override
public boolean ownDeletesAreVisible(int type) throws SQLException {
return false;
}
@Override
public boolean ownInsertsAreVisible(int type) throws SQLException {
return false;
}
@Override
public boolean othersUpdatesAreVisible(int type) throws SQLException {
return false;
}
@Override
public boolean othersDeletesAreVisible(int type) throws SQLException {
return false;
}
@Override
public boolean othersInsertsAreVisible(int type) throws SQLException {
return false;
}
@Override
public boolean updatesAreDetected(int type) throws SQLException {
return false;
}
@Override
public boolean deletesAreDetected(int type) throws SQLException {
return false;
}
@Override
public boolean insertsAreDetected(int type) throws SQLException {
return false;
}
@Override
public boolean supportsBatchUpdates() throws SQLException {
return false;
}
@Override
public ResultSet getUDTs(String catalog, String schemaPattern, String typeNamePattern, int[] types) throws SQLException {
return null;
}
@Override
public Connection getConnection() throws SQLException {
return null;
}
@Override
public boolean supportsSavepoints() throws SQLException {
return false;
}
@Override
public boolean supportsNamedParameters() throws SQLException {
return false;
}
@Override
public boolean supportsMultipleOpenResults() throws SQLException {
return false;
}
@Override
public boolean supportsGetGeneratedKeys() throws SQLException {
return false;
}
@Override
public ResultSet getSuperTypes(String catalog, String schemaPattern, String typeNamePattern) throws SQLException {
return null;
}
@Override
public ResultSet getSuperTables(String catalog, String schemaPattern, String tableNamePattern) throws SQLException {
return null;
}
@Override
public ResultSet getAttributes(String catalog, String schemaPattern, String typeNamePattern, String attributeNamePattern) throws SQLException {
return null;
}
@Override
public boolean supportsResultSetHoldability(int holdability) throws SQLException {
return false;
}
@Override
public int getResultSetHoldability() throws SQLException {
return 0;
}
@Override
public int getDatabaseMajorVersion() throws SQLException {
return 0;
}
@Override
public int getDatabaseMinorVersion() throws SQLException {
return 0;
}
@Override
public int getJDBCMajorVersion() throws SQLException {
return 0;
}
@Override
public int getJDBCMinorVersion() throws SQLException {
return 0;
}
@Override
public int getSQLStateType() throws SQLException {
return 0;
}
@Override
public boolean locatorsUpdateCopy() throws SQLException {
return false;
}
@Override
public boolean supportsStatementPooling() throws SQLException {
return false;
}
@Override
public RowIdLifetime getRowIdLifetime() throws SQLException {
return null;
}
@Override
public ResultSet getSchemas(String catalog, String schemaPattern) throws SQLException {
return null;
}
@Override
public boolean supportsStoredFunctionsUsingCallSyntax() throws SQLException {
return false;
}
@Override
public boolean autoCommitFailureClosesAllResultSets() throws SQLException {
return false;
}
@Override
public ResultSet getClientInfoProperties() throws SQLException {
return null;
}
@Override
public ResultSet getFunctions(String catalog, String schemaPattern, String functionNamePattern) throws SQLException {
return null;
}
@Override
public ResultSet getFunctionColumns(String catalog, String schemaPattern, String functionNamePattern, String columnNamePattern) throws SQLException {
return null;
}
@Override
public ResultSet getPseudoColumns(String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern) throws SQLException {
return null;
}
@Override
public boolean generatedKeyAlwaysReturned() throws SQLException {
return false;
}
@Override
public <T> T unwrap(Class<T> iface) throws SQLException {
return null;
}
@Override
public boolean isWrapperFor(Class<?> iface) throws SQLException {
return false;
}
}

View file

@ -0,0 +1,75 @@
/*
* Copyright (c) 2014, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package util;
import java.sql.Connection;
import java.sql.Driver;
import java.sql.DriverPropertyInfo;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.util.Properties;
import java.util.logging.Logger;
public class StubDriver implements Driver {
public StubDriver() {
}
@Override
public Connection connect(String url, Properties info) throws SQLException {
if (acceptsURL(url)) {
return new StubConnection();
}
return null;
}
@Override
public boolean acceptsURL(String url) throws SQLException {
return url.matches("^jdbc:tennis:.*");
}
@Override
public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public int getMajorVersion() {
return 1;
}
@Override
public int getMinorVersion() {
return 0;
}
@Override
public boolean jdbcCompliant() {
return true;
}
@Override
public Logger getParentLogger() throws SQLFeatureNotSupportedException {
throw new UnsupportedOperationException("Not supported yet.");
}
}

View file

@ -0,0 +1,75 @@
/*
* Copyright (c) 2014, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package util;
import java.io.File;
import java.io.IOException;
import java.sql.DriverAction;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* Simple java.sql.Driver stub class that registers the driver via a static
* block with a DriverAction Implementation
* @author ljanders
*/
public class StubDriverDA extends StubDriver {
public static final String DriverActionCalled = "DriverActionCalled.txt";
static DriverAction da;
static {
try {
DriverManager.registerDriver(new StubDriverDA(), da);
} catch (SQLException ex) {
Logger.getLogger(StubDriverDA.class.getName()).log(Level.SEVERE, null, ex);
}
}
public StubDriverDA() {
da = new DriverActionImpl(this);
}
@Override
public boolean acceptsURL(String url) throws SQLException {
return url.matches("^jdbc:luckydog:.*");
}
/**
* This method will write out a text file when called by the
* DriverActionImpl.release method when DriverManager.deregisterDriver
* is called. This is used by DriverManagerTests to validate that
* DriverAction.release was called
*/
protected void release() {
File file = new File(DriverActionCalled);
try {
file.createNewFile();
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
}

View file

@ -0,0 +1,312 @@
/*
* Copyright (c) 2015, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package util;
import java.io.InputStream;
import java.io.Reader;
import java.math.BigDecimal;
import java.net.URL;
import java.sql.*;
import java.util.Calendar;
public class StubPreparedStatement extends StubStatement implements PreparedStatement{
public StubPreparedStatement(StubConnection con) {
super(con);
}
@Override
public ResultSet executeQuery() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public int executeUpdate() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setNull(int parameterIndex, int sqlType) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setBoolean(int parameterIndex, boolean x) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setByte(int parameterIndex, byte x) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setShort(int parameterIndex, short x) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setInt(int parameterIndex, int x) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setLong(int parameterIndex, long x) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setFloat(int parameterIndex, float x) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setDouble(int parameterIndex, double x) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setBigDecimal(int parameterIndex, BigDecimal x) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setString(int parameterIndex, String x) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setBytes(int parameterIndex, byte[] x) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setDate(int parameterIndex, Date x) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setTime(int parameterIndex, Time x) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setTimestamp(int parameterIndex, Timestamp x) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setAsciiStream(int parameterIndex, InputStream x, int length) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setUnicodeStream(int parameterIndex, InputStream x, int length) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setBinaryStream(int parameterIndex, InputStream x, int length) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void clearParameters() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setObject(int parameterIndex, Object x, int targetSqlType) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setObject(int parameterIndex, Object x) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public boolean execute() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void addBatch() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setCharacterStream(int parameterIndex, Reader reader, int length) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setRef(int parameterIndex, Ref x) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setBlob(int parameterIndex, Blob x) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setClob(int parameterIndex, Clob x) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setArray(int parameterIndex, Array x) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public ResultSetMetaData getMetaData() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setDate(int parameterIndex, Date x, Calendar cal) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setTime(int parameterIndex, Time x, Calendar cal) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setTimestamp(int parameterIndex, Timestamp x, Calendar cal) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setNull(int parameterIndex, int sqlType, String typeName) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setURL(int parameterIndex, URL x) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public ParameterMetaData getParameterMetaData() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setRowId(int parameterIndex, RowId x) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setNString(int parameterIndex, String value) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setNCharacterStream(int parameterIndex, Reader value, long length) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setNClob(int parameterIndex, NClob value) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setClob(int parameterIndex, Reader reader, long length) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setBlob(int parameterIndex, InputStream inputStream, long length) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setNClob(int parameterIndex, Reader reader, long length) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setSQLXML(int parameterIndex, SQLXML xmlObject) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setObject(int parameterIndex, Object x, int targetSqlType, int scaleOrLength) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setAsciiStream(int parameterIndex, InputStream x, long length) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setBinaryStream(int parameterIndex, InputStream x, long length) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setCharacterStream(int parameterIndex, Reader reader, long length) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setAsciiStream(int parameterIndex, InputStream x) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setBinaryStream(int parameterIndex, InputStream x) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setCharacterStream(int parameterIndex, Reader reader) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setNCharacterStream(int parameterIndex, Reader value) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setClob(int parameterIndex, Reader reader) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setBlob(int parameterIndex, InputStream inputStream) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setNClob(int parameterIndex, Reader reader) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
}

View file

@ -0,0 +1,258 @@
/*
* Copyright (c) 2015, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package util;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.SQLWarning;
import java.sql.Statement;
public class StubStatement implements Statement {
protected final Connection con;
public StubStatement(StubConnection con) {
this.con = con;
}
@Override
public ResultSet executeQuery(String sql) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public int executeUpdate(String sql) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void close() throws SQLException {
con.close();
}
@Override
public int getMaxFieldSize() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setMaxFieldSize(int max) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public int getMaxRows() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setMaxRows(int max) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setEscapeProcessing(boolean enable) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public int getQueryTimeout() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setQueryTimeout(int seconds) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void cancel() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public SQLWarning getWarnings() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void clearWarnings() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setCursorName(String name) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public boolean execute(String sql) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public ResultSet getResultSet() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public int getUpdateCount() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public boolean getMoreResults() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setFetchDirection(int direction) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public int getFetchDirection() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setFetchSize(int rows) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public int getFetchSize() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public int getResultSetConcurrency() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public int getResultSetType() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void addBatch(String sql) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void clearBatch() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public int[] executeBatch() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Connection getConnection() throws SQLException {
return con;
}
@Override
public boolean getMoreResults(int current) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public ResultSet getGeneratedKeys() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public int executeUpdate(String sql, int[] columnIndexes) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public int executeUpdate(String sql, String[] columnNames) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public boolean execute(String sql, int autoGeneratedKeys) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public boolean execute(String sql, int[] columnIndexes) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public boolean execute(String sql, String[] columnNames) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public int getResultSetHoldability() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public boolean isClosed() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setPoolable(boolean poolable) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public boolean isPoolable() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void closeOnCompletion() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public boolean isCloseOnCompletion() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public <T> T unwrap(Class<T> iface) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public boolean isWrapperFor(Class<?> iface) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
}