How-to articles, tricks, and solutions about JDBC

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure is an exception that is thrown when there is a failure in the communication link between your Java program and the MySQL database. This can happen for a variety of reason

Connect Java to a MySQL database

To connect a Java application to a MySQL database, you need to use the JDBC (Java Database Connectivity) API.

How do I connect to a SQL Server 2008 database using JDBC?

To connect to a SQL Server database using JDBC, you will need to use the JDBC driver for SQL Server.

How do I find out my MySQL URL, host, port and username?

To find out your MySQL connection details, you will need to look in your MySQL configuration files. The specific location of these files will depend on how you installed MySQL, but common locations include /etc/my.cnf,

How to connect to Oracle using Service Name instead of SID

To connect to an Oracle database using a service name instead of a SID (System Identifier), you can use the thin driver and specify the connection URL in the following format:

How to get row count using ResultSet in Java?

To get the row count using a ResultSet object in Java, you can use the last() method to move the cursor to the last row, and then use the getRow() method to get the row number:

Java ResultSet how to check if there are any results

To check if a ResultSet object contains any results in Java, you can use the next method of the ResultSet class.

java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)

A java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES) error typically indicates that the MySQL server is unable to authenticate the user with the provided username and password.

MySQL JDBC Driver 5.1.33 - Time Zone Issue

If you are using MySQL JDBC Driver version 5.1.33 and you are experiencing issues with time zones, there are a few things you can try:

Solving a "communications link failure" with JDBC and MySQL

A "communications link failure" error when using JDBC and MySQL can be caused by several factors. Here are a few potential solutions: