⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 simpletable.java

📁 这是一本描述JDBC数据库的书籍
💻 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){                            }        }    }    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -