Quick revision
The short answer
For Oracle the driver is com.oracle.database.jdbc:ojdbc11 (or ojdbc17 for newer JDKs; check your version), with URLs like jdbc:oracle:thin:@//host:1521/service. For SQL Server it is com.microsoft.sqlserver:mssql-jdbc, with URLs like jdbc:sqlserver://host:1433;databaseName=db;encrypt=true. Behaviour differences a PostgreSQL developer notices quickly: Oracle stores an empty string as NULL, Oracle fetches only 10 rows per round trip by default, and SQL Server's driver sends String parameters as NVARCHAR by default, which can stop indexes on VARCHAR columns from being used.
What to remember
In this answer, we set up the Oracle driver, com.oracle.database.jdbc:ojdbc11 or ojdbc17 depending on the JDK, with jdbc:oracle:thin:@//host:1521/service, and the SQL Server driver, com.microsoft.sqlserver:mssql-jdbc, with jdbc:sqlserver://host:1433;databaseName=db;encrypt=true. We then saw three behaviour differences from PostgreSQL: Oracle turns empty strings into NULL, Oracle fetches 10 rows per round trip unless we raise the fetch size, and SQL Server's driver sends Strings as NVARCHAR, which can prevent index seeks on VARCHAR columns.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
For Oracle the driver is com.oracle.database.jdbc:ojdbc11 (or ojdbc17 for newer JDKs; check your version), with URLs like jdbc:oracle:thin:@//host:1521/service. For SQL Server it is com.microsoft.sqlserver:mssql-jdbc, with URLs like jdbc:sqlserver://host:1433;databaseName=db;encrypt=true. Behaviour differences a PostgreSQL developer notices quickly: Oracle stores an empty string as NULL, Oracle fetches only 10 rows per round trip by default, and SQL Server's driver sends String parameters as NVARCHAR by default, which can stop indexes on VARCHAR columns from being used.
Why this question is asked
Most Java developers learn database access on one engine, often PostgreSQL, and then carry its assumptions to the next project. The connection details are easy to look up, but the behaviour differences are what cause bugs and slow queries in the first week. Interviewers ask this to see whether we have real hands-on experience with these drivers. In this answer, we will set up both drivers with Maven coordinates and URLs, and then look at the three behaviour differences, each with an example and a fix.
1Connecting to Oracle
Oracle publishes its JDBC driver on Maven Central under com.oracle.database.jdbc. The artifact name says which Java version it is compiled for: ojdbc8 for Java 8 and later, ojdbc11 for Java 11 and later, and with the newer 23ai driver line, ojdbc17 for Java 17 and later. Check your version against the driver's support matrix, since the database release and the driver release are separate.
The thin driver is pure Java and needs no Oracle client installed. The //host:port/service form uses a service name, which is what modern Oracle, including pluggable databases, expects. The older host:port:SID form with colons still appears in legacy configurations.
2Connecting to SQL Server
Microsoft's driver is com.microsoft.sqlserver:mssql-jdbc, published with version suffixes such as .jre11 that name the minimum Java version. The URL uses semicolon-separated properties.
Notice encrypt=true. Recent driver versions encrypt by default and validate the server certificate, which surprises teams upgrading from older drivers against servers with self-signed certificates. Setting trustServerCertificate=true makes the error go away but disables certificate validation, so it is acceptable only for local development; in production the server needs a trusted certificate.
3Difference 1: Oracle Treats an Empty String as NULL
In PostgreSQL, an empty string and NULL are different values. In Oracle, a VARCHAR2 column cannot hold an empty string: inserting '' stores NULL. Code that writes '' for 'no middle name' and later looks for it with = '' finds nothing, and a NOT NULL column rejects the empty string.
The safest fix is a single rule in the domain: represent missing values as null, never as an empty string, and normalise input at the edge of the application. That behaves the same on every engine.
4Difference 2: Oracle's Default Fetch Size of 10
When we iterate a ResultSet, the driver does not fetch all rows at once; it fetches a number of rows per round trip, the fetch size. The Oracle driver's default is 10 rows. Reading 100,000 rows therefore takes 10,000 round trips, and at 1 ms each that is 10 seconds of pure waiting. PostgreSQL's driver, by contrast, by default reads the whole result into memory in one go, unless we set a fetch size inside a transaction, so the same code feels fast there and slow on Oracle.
A larger fetch size uses more memory per open cursor, so we pick a value like 100 to 1,000 rather than an extreme one, and set it higher for known bulk reads.
5Difference 3: SQL Server Sends Strings as NVARCHAR
By default, mssql-jdbc sends every String parameter as NVARCHAR, Unicode text, because the property sendStringParametersAsUnicode defaults to true. If the column is VARCHAR, SQL Server must convert the column to NVARCHAR to compare, because NVARCHAR has the higher type precedence. Depending on the collation, that conversion can stop SQL Server from seeking in the index, so it scans instead.
| Behaviour | PostgreSQL | Oracle | SQL Server |
|---|---|---|---|
| Empty string | Stored as '' | Stored as NULL | Stored as '' |
| Default fetch | All rows at once | 10 rows per round trip | Adaptive buffering |
| String parameters | text/varchar | VARCHAR2 | NVARCHAR unless configured |
| Boolean column type | boolean | BOOLEAN only from 23ai | bit |
PostgreSQL has nothing like this, because its text types do not split into Unicode and non-Unicode variants, so developers coming from it rarely expect a parameter type to change a query plan.
6Follow-up questions
Which Hibernate dialect setting do you need?
Usually none. Hibernate 6 and later detect the database and version from the JDBC connection metadata and pick OracleDialect or SQLServerDialect automatically. Setting hibernate.dialect explicitly is only needed in special cases, and old version-specific dialect class names are deprecated.
Why does SQL Server compare strings case-insensitively?
Because the default collation for most installations is case-insensitive, such as SQL_Latin1_General_CP1_CI_AS, where CI means case-insensitive. So WHERE code = 'abc' matches 'ABC' on SQL Server but not on PostgreSQL, which is another difference that tests on one engine will not catch.
How do identifiers differ?
Oracle upper-cases unquoted identifiers, PostgreSQL lower-cases them, and SQL Server keeps them as written but compares them by the database collation. If an entity maps a table name in quotes with mixed case, it may work on one engine and fail on another, so we keep names unquoted and in one case.
7Conclusion
In this answer, we set up the Oracle driver, com.oracle.database.jdbc:ojdbc11 or ojdbc17 depending on the JDK, with jdbc:oracle:thin:@//host:1521/service, and the SQL Server driver, com.microsoft.sqlserver:mssql-jdbc, with jdbc:sqlserver://host:1433;databaseName=db;encrypt=true. We then saw three behaviour differences from PostgreSQL: Oracle turns empty strings into NULL, Oracle fetches 10 rows per round trip unless we raise the fetch size, and SQL Server's driver sends Strings as NVARCHAR, which can prevent index seeks on VARCHAR columns.
Open with
For Oracle the Maven coordinates are com.oracle.database.jdbc with the artifact ojdbc11 for Java 11 and later, or ojdbc17 with the newer driver line for Java 17, and I would check the support matrix for the exact version.
Then, if they want more
The thin URL is jdbc:oracle:thin:@//host:1521/service_name, and older systems use the host:port:SID form. For SQL Server it is com.microsoft.sqlserver:mssql-jdbc, and the URL is jdbc:sqlserver://host:1433;databaseName=orders;encrypt=true. Recent drivers encrypt and validate certificates by default, so trustServerCertificate should only be true locally.
Coming from PostgreSQL, the first difference I would mention is that Oracle stores an empty string as NULL, so code that writes empty strings breaks NOT NULL columns and equality checks; I would represent missing values as null everywhere.
The second is that the Oracle driver fetches only 10 rows per round trip by default, so a 100,000 row read takes 10,000 round trips; I set setFetchSize or defaultRowPrefetch to a few hundred. And on SQL Server, the driver sends String parameters as NVARCHAR by default.
Against a VARCHAR indexed column that can cause an implicit conversion and an index scan instead of a seek, so for VARCHAR databases I set sendStringParametersAsUnicode=false and use setNString for the Unicode columns.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Hibernate 6, Java 11, Java 17, Java 8
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- PostgreSQL documentation, MySQL reference manual
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Name the JDBC driver coordinates and typical URL formats for Oracle and SQL Server, and...": https://scrivio-interview-library.netlify.app/databases/oracle-and-sql-server/655ec87abf/