Online Training Spring Hibernate Training in Delhi R Programming Training Course Big Data and Hadoop Training Java Training  

How can I connect my database to my application ?



Share on Google+Share on Google+

Nitin Sapra
How can I connect my database to my application ?
1 Answer(s)      6 years and 10 months ago
Posted in : Java Beginners

How can I connect my database to my application?

View Answers

October 21, 2010 at 2:20 PM


You can use JDBC API to connect to database from your Java application.

Here is the sample code to connect to database:

import java.sql.*;

public class ConnetToDatabase {
  public static void main(String[] args) {
    try {
      Connection conn = DriverManager.getconnnection(
          "jdbc:mysql://localhost:3306/test", "root", "root");
      Statement statement = conn.createStatement();
      DatabaseMetaData meta = conn.getMetaData();
      ResultSet rs = meta.getTables(null, null, "%", null);
      String tableNames = "";
      while ( {
        tableNames = rs.getString(3);
    } catch (Exception e) {

Read more at JDBC Tutorials Thanks


Related Tutorials/Questions & Answers: