package com.struts1.tutorials.ejb.orders;
import java.sql.*;
public class TestDB {
private static final String SQL_QUERY1 = "SELECT * FROM customers";
private static final String JDBC_DRIVER = "oracle.jdbc.OracleDriver";
private static final String DB_URL = "jdbc:oracle:thin:@//localhost:1521/xe";
private static final String DB_USR = "lakshman01";
private static final String DB_PWD = "passwd";
public static void main(String[] args) {
Connection conn = null;
Statement stmt = null;
ResultSet rset = null;
try {
Class.forName (JDBC_DRIVER);
conn = DriverManager.getConnection(DB_URL, DB_USR, DB_PWD);
stmt = conn.createStatement();
rset = stmt.executeQuery(SQL_QUERY1);
while (rset.next()) {
System.out.println ("Customer ID = " + rset.getInt("CUSTOMER_ID"));
System.out.println ("Customer Name = " + rset.getString("CUSTOMER_NAME"));
}
}
catch (Exception ex) {
ex.printStackTrace();
}
finally {
try {
if (rset != null)
rset.close();
} catch (Exception ignore) {}
try {
if (stmt != null)
stmt.close();
} catch (Exception ignore) {}
try {
if (conn != null)
conn.close();
} catch (Exception ignore) {}
}
}
}
import java.sql.*;
public class TestDB {
private static final String SQL_QUERY1 = "SELECT * FROM customers";
private static final String JDBC_DRIVER = "oracle.jdbc.OracleDriver";
private static final String DB_URL = "jdbc:oracle:thin:@//localhost:1521/xe";
private static final String DB_USR = "lakshman01";
private static final String DB_PWD = "passwd";
public static void main(String[] args) {
Connection conn = null;
Statement stmt = null;
ResultSet rset = null;
try {
Class.forName (JDBC_DRIVER);
conn = DriverManager.getConnection(DB_URL, DB_USR, DB_PWD);
stmt = conn.createStatement();
rset = stmt.executeQuery(SQL_QUERY1);
while (rset.next()) {
System.out.println ("Customer ID = " + rset.getInt("CUSTOMER_ID"));
System.out.println ("Customer Name = " + rset.getString("CUSTOMER_NAME"));
}
}
catch (Exception ex) {
ex.printStackTrace();
}
finally {
try {
if (rset != null)
rset.close();
} catch (Exception ignore) {}
try {
if (stmt != null)
stmt.close();
} catch (Exception ignore) {}
try {
if (conn != null)
conn.close();
} catch (Exception ignore) {}
}
}
}
No comments:
Post a Comment