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();
}
}
}
Hi, my name is Zemian Deng, and I enjoy programming. I use this blog to keep some of my technical journals. I hope these articles can be the salt and light for others in the community. Feel free to make comments and send me your thoughts.
Saturday, December 8, 2012
Checking DB Connection using Java
For complete sake, here is a Java version of the Groovy post to test your Oracle Database connection.
Subscribe to:
Post Comments (Atom)