Functional Testing Interview Questions & Answers Testing Fundamentals

Database Testing | How do you get a Database Connection?

How do you get a Database connection?” the interviewer asked. That was simple, right. Using a Database connection string I said. But what do you pass in connection string and how does it works at the back-end? Oh Oh! They need the details. As a tester, most of the testing is centered on web applications (i.e. browser) and now-a-days mobile apps. But as with API testing, Database testing & SQL is growing in demand. Database knowledge is something every tester is expected to know about. So with this article we try to explain how to connect to a database, in detail.

Get Database Connection

An application connects to a database using Database Connection APIs (JDBC/ODBC/etc. which implement Driver Manager) and particular Database Drivers. Database drivers are client-side adapters (installed on the client machine, not on the server) that convert requests from programs (Java/C/C++/etc.) to a protocol that the DBMS can understand.

Every API implements a getConnection() method to connect to a database. We need to pass a ‘Connection string’ that specifies information about a data source and the means of connecting to it. It is passed in code to an underlying driver in order to initiate the database connection. The connection string may include attributes such as,

  • Driver Name
  • Server Name (Host)
  • Database Name (or Service Name)
  • Port Number (the database listener is using)
  • Username/Password

The connection string used is dependent upon the particular API, Database and the Driver used. It is specific to a particular DBMS.


  • MySQL: jdbc:mysql://localhost:3306/test, where JDBC is the connection API, mysql is the DBMS, localhost is Server name, 3306 is Port number, and ‘test’ is the Database name.
  • Postgres connection string for connecting to with SSL and a connection timeout of 180 seconds: DRIVER={PostgreSQL Unicode};;SSL=true;SSLMode=require;DATABASE=wiki;UID=wikiuser;Connect Timeout=180;PWD=password

All the methods return a Connection object which is used for making SQL queries to the connected database.


ODBC Database Connection Details

Open Database Connectivity (ODBC) is a Microsoft specification for an API that constitutes an implementation of the International standards for the SQL CLI.

Sun Microsystems developed a specification, called JDBC that defines an API for the Java™ programming environment that Java programmers use to access relational databases and issue SQL statements. The JDBC specification defines many of the same types of functions for Java programmers that ODBC and the SQL CLI define for C and C++ programmers. JDBC constitutes a super-set of the SQL CLI, since it defines many functions that the International standards for the SQL CLI do not define.

OLE DB was designed as a higher-level replacement for ODBC to support a wider variety of non-relational database connection that do not necessarily implement SQL (for example, object databases and spreadsheets). OLE has a client-provider model, where clients request access to data, and providers are the software component interfaces that allow access to the data.

Database Drivers

ODBC is based on the device driver model, where the driver encapsulates the logic needed to convert a standard set of commands and functions into the specific calls required by the underlying system. In the case of ODBC, the drivers encapsulate many functions that can be broken down into several broad categories.

  • One set of functions is primarily concerned with finding, connecting to and disconnecting from the DBMS that driver talks to.
  • A second set is used to send SQL commands from the ODBC system to the DBMS, converting or interpreting any commands that are not supported internally.
  • Another set of commands, mostly used internally, is used to convert data from the DBMS’s internal formats to a set of standardized ODBC formats, which are based on the C language formats.

ODBC drivers exist for most DBMSs, including Oracle, PostgreSQL, MySQL, Microsoft SQL Server, Sybase ASE, SAP HANA and DB2.

Database Driver Manager

Device drivers are normally enumerated, set up and managed by a separate Manager layer, which may provide additional functionality. In ODBC the Driver Manager (DM) provides these features. The DM can enumerate the installed drivers and present this as a list, often in a GUI-based form.

JDBC Database Connection

More important to the operation of the ODBC system is the DM’s concept of a Data Source Name (DSN). DSNs collect additional information needed to connect to a specific data source, versus the DBMS itself. For instance, the same MySQL driver can be used to connect to any MySQL server, but the connection information to connect to a local private server is different from the information needed to connect to an internet-hosted public server. The DSN stores this information in a standardized format, and the DM provides this to the driver during connection requests. The DM also includes functionality to present a list of DSNs using human readable names, and to select them at run-time to connect to different resources.

Quick Tips

  • You can add the name of the database to the TNSNames in your DB client.
  • Log onto the Database Server and start a DOS command line window. Enter lsnrctl status. This will give you the database name and port and if the listener is ready to receive connections.
  • JDBC API requires drivers for each database. The driver gives out the database connection and implements the protocol for transferring the query and result between client and database.
  • ODBC accomplishes DBMS independence by using an ODBC driver as a translation layer between the application and the DBMS. The application uses ODBC functions through an ODBC driver manager with which it is linked, and the driver passes the query to the DBMS. Any ODBC-compliant application can access any DBMS for which a driver is installed. Drivers exist for all major DBMSs, many other data sources like address book systems and Microsoft Excel, and even for text or comma-separated values (CSV) files.

Hope this helps in clarifying few of the doubts testers have when connecting to a database. Or will help in acquiring a database connection in your next database test 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *