
Resultset = stmt.executeQuery("SHOW DATABASES ") execute the query via connection object Static String password = "password" // replace with your MySQL client password Static String username = "username" // replace with your MySQL client username * Program to list databases in MySQL Server using Java MySQLDatabaseExample.java import java.sql.* Also, if the MySQL Server is running on another machine, replace the localhost IP and port with appropriate MySQL Server IP and port. Replace username and password with credentials you have used while creating a user in MySQL. Close ResultSet, Statement and Connection Once the desired operation with MySQL Server is completed, close the jdbc resources that we have created in the program like ResultSet, Statement and Connection in the order that we first close the resource that is created last of all, to ensure that any dependency is not violated.Įxample 1 – List databases in MySQL Server using Java.ResultSet has the list of databases Execution in the above step returns a ResultSet containing the names of databases.Execute this query with the help of Statement class. Execute query to list databases “SHOW DATABASES ” is the SQL query that fetches the databases’ list.
#Mysql list databases on server driver
Establish connection to MySQL Server Create a new mysql JDBC Driver instance and make a connection to the MySQL Server.In this tutorial, we shall learn to list databases in MySQL Server using Java with the help of JDBC classes.įollowing is step by step process to list available databases in mysql : MySQL is used to manage relational databases and it can contain multiple databases to serve different applications. Read contents of a File line by line using Stream.



Replace multiple spaces with single space.Get character at specific index in string.Check if string contains search substring.Check if string starts with specific prefix.Check if string ends with specific suffix.Get index of nth occurrence of substring.Get index of the first Occurrence of substring.
