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

📄 datasource.java

📁 Java示例100
💻 JAVA
字号:
/** * A Simple DataSource sample without using JNDI. * Please compare to DataSourceJNDI.java * * Please use jdk1.2 or later version */// You need to import the java.sql package to use JDBCimport java.sql.*;import javax.sql.*;import oracle.jdbc.*;import oracle.jdbc.pool.OracleDataSource;public class DataSource{  public static void main (String args [])    throws SQLException  {    // Create a OracleDataSource instance explicitly    OracleDataSource ods = new OracleDataSource();    // Set the user name, password, driver type and network protocol    ods.setUser("hr");    ods.setPassword("hr");    ods.setDriverType("oci8");    ods.setNetworkProtocol("ipc");    // Retrieve a connection    Connection conn = ods.getConnection();    getUserName(conn);    // Close the connection    conn.close();    conn = null;  }  static void getUserName(Connection conn)       throws SQLException  {    // Create a Statement    Statement stmt = conn.createStatement ();    // Select the USER column from the dual table    ResultSet rset = stmt.executeQuery ("select USER from dual");    // Iterate through the result and print the USER    while (rset.next ())      System.out.println ("User name is " + rset.getString (1));    // Close the RseultSet    rset.close();    rset =  null;    // Close the Statement    stmt.close();    stmt = null;  }}

⌨️ 快捷键说明

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