📄 definecolumntype.java
字号:
/* * This sample shows how to use the "define" extensions. * The define extensions allow the user to specify the types * under which to retrieve column data in a query. * * This saves round-trips to the database (otherwise necessary to * gather information regarding the types in the select-list) and * conversions from native types to the types under which the user * will get the data. * * This can also be used to avoid streaming of long columns, by defining * them as CHAR or VARCHAR types. */// You need to import the java.sql package to use JDBCimport java.sql.*;// You need to import oracle.jdbc.driver.* in order to use the// API extensions.import oracle.jdbc.driver.*;class DefineColumnType{ public static void main (String args []) throws SQLException { // Load the Oracle JDBC driver DriverManager.registerDriver( new oracle.jdbc.driver.OracleDriver()); // Connect to the database // You can put a database name after the @ sign in the connection URL. Connection conn = DriverManager.getConnection ("jdbc:oracle:oci8:@", "scott", "tiger"); Statement stmt = conn.createStatement (); // Call DefineColumnType to specify that the column will be // retrieved as a String to avoid conversion from NUMBER to String // on the client side. This also avoids a round-trip to the // database to get the column type. // // There are 2 defineColumnType API. We use the one with 3 arguments. // The 3rd argument allows us to specify the maximum length // of the String. The values obtained for this column will // not exceed this length. ((OracleStatement)stmt).defineColumnType (1, Types.VARCHAR, 7); ResultSet rset = stmt.executeQuery ("select empno from emp"); while (rset.next ()) { System.out.println (rset.getString (1)); } // Close the resultSet rset.close(); // Close the statement stmt.close (); // Close the connection conn.close(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -