DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • How to Identify the Underlying Causes of Connection Timeout Errors for MongoDB With Java
  • Jakarta WebSocket Essentials: A Guide to Full-Duplex Communication in Java
  • Step by Step Guide to Create Mule Custom Connector Using Java SDK
  • Jakarta NoSQL: Why JPA Is Not Enough for the AI Era

Trending

  • Top Java Security Vulnerabilities and How to Prevent Them in Modern Java
  • From printTriangularNumber to Duff’s Device: Mastering Java Switch Statements Old and New
  • The ORM Is Over: AI-Written SQL Is the New Data Access Layer
  • Your AI Is Not Failing, Your Context Is
  1. DZone
  2. Coding
  3. Java
  4. Checking DB Connection Using Java

Checking DB Connection Using Java

By 
Zemian Deng user avatar
Zemian Deng
·
Dec. 14, 12 · Interview
Likes (0)
Comment
Save
Tweet
Share
60.8K Views

Join the DZone community and get the full member experience.

Join For Free

For the sake of completeness, here is a Java version of the Groovy post to test your Oracle Database connection.  

package atest;
import java.sql.*;
/**
 * Run arguments sample:
 * jdbc:oracle:thin:@localhost:1521:XE system mypassword123 oracle.jdbc.driver.OracleDriver
 */
public class DbConn {
    public static void main(String[] args) throws Exception {
        String url = args[0];
        String username = args[1];
        String password = args[2];
        String driver = args[3];

        Class.forName(driver);
        Connection conn = DriverManager.getConnection(url, username, password);
        try {
            Statement statement = conn.createStatement();
            ResultSet rs = statement.executeQuery("SELECT SYSDATE FROM DUAL");
            while(rs.next()) {
                System.out.println(rs.getObject(1));
            }
        } finally {
            conn.close();
        }
    }
}
Java (programming language) Connection (dance)

Published at DZone with permission of Zemian Deng. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • How to Identify the Underlying Causes of Connection Timeout Errors for MongoDB With Java
  • Jakarta WebSocket Essentials: A Guide to Full-Duplex Communication in Java
  • Step by Step Guide to Create Mule Custom Connector Using Java SDK
  • Jakarta NoSQL: Why JPA Is Not Enough for the AI Era

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook