?? simpletable.java
字號:
/* * SimpleTable.java * * Created on June 9, 2005, 10:44 AM * * To change this template, choose Tools | Options and locate the template under * the Source Creation and Management node. Right-click the template and choose * Open. You can then make changes to the template in the Source Editor. */package ch01;import java.sql.*;import javax.sql.*;import oracle.jdbc.driver.*;/** * * @author kevin */public class SimpleTable { /** Creates a new instance of SimpleTable */ public SimpleTable() { } public static void main(String[] args){ Connection conn = null; Statement stmt = null; ResultSet rs = null; try{ /* * Class.forName("oracle.jdbc.driver.OracleDriver"); * connection = DriverManager.getConnection(dbURL, user, password); * * * DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver()); * connection = DriverManager.getConnection(dbUrl, user, password); * * System.setProperty("jdbc.drivers", "oracle.jdbc.driver.OracleDriver"); * connection = DriverManager.getConnection(dbUrl, user, password); * * java -Doracle.jdbc.driver.OracleDriver:XXXX:XXXXX * connection = DriverManager.getConnection(dbUrl, user, password); * * */ //1 register the driver Driver driver = new OracleDriver(); DriverManager.registerDriver(driver); /** * Properties props = new Properties(); * props.put("user", "jdbc"); * props.put("password", "jdbc"); * DriverManager.getConnection(url, props); * * conn = driver.connect(url, props); */ //2 get a connection from DriverManager conn = DriverManager.getConnection( "jdbc:oracle:thin:@localhost:1521:kevin", "jdbc", "jdbc"); //3 create a statement stmt = conn.createStatement(); //4 execute SQL rs = stmt.executeQuery("select id, name from simple_tbl"); //5 processing the result set while(rs.next()){ long id = rs.getLong("id"); String name = rs.getString("name"); System.out.println("ID: " + id + "\tName: " + name); } }catch(SQLException e){ e.printStackTrace(); }finally{ //6 close the objects try{ if(rs != null)rs.close(); if(stmt != null)stmt.close(); if(conn != null)conn.close(); }catch(SQLException e){ } } } }
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -