oracle jdbc example 示例

package wcg.test.jdbc.oracle;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class TestConnOracle {

	/**
	 * @param args
	 */
	public static void main(String[] args) throws Exception {

		Connection conn = null;
		Class.forName("oracle.jdbc.driver.OracleDriver"); 
		conn = DriverManager
				.getConnection("jdbc:oracle:thin:@localhost:1521:XE","rms","rms");
		Statement stmt = conn.createStatement();
		ResultSet rs = stmt.executeQuery("select * from  SPARK.WCG_USERS");
		while (rs.next()) {
			System.out.println(rs.getInt(1));
			System.out.println(rs.getString("USERNAME"));
			System.out.println(rs.getString("PASSWORD"));
			System.out.println("----------");
		}

		try {
			if (rs != null) {
				rs.close();
				rs = null;
			}
			if (stmt != null) {
				stmt.close();
				stmt = null;
			}
			if (conn != null) {
				conn.close();
				conn = null;
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}

	}

}
posted @ 2011-07-14 11:00  庚武  Views(636)  Comments(0Edit  收藏  举报