📄 first.java~2~
字号:
package sfms;import java.sql.*;public class first{ public static void main(String args[]){ //declare Connection and Statement objects Connection conn=null; Statement state=null; try{ //register the Oracle JDBC drivers Class.forName("oracle.jdbc.OracleDriver").newInstance(); //create a Connection object,and connect to the database //as df using the Oracle JDBC thin driver conn=DriverManager.getConnection( "jdbc:oracle:thin:@localhost:1521:SFMS", "df","1234" ); //create a Statement object state=conn.createStatement(); //create a ResultSet object,and populate it with the //result of SELECT statement that retrieves the user //and sysdate variables from the database via the dual //table -the executeQuery() method of the Statement object //is used to perform the SELECT ResultSet result=state.executeQuery( "SELECT user,sysdate"+ "FROM dual" ); //retrieve the user from the row in the Resultset using //the next() method String user=result.getString("user"); //retrieve the sysdate from the row in the ResultSet using //the getTimestamp() method Timestamp dateTime= result.getTimestamp("sysdate"); System.out.print("Hello "+user+ ", the current date and time is "+dateTime); //close this ResultSet object using the close() method result.close(); } catch(SQLException e){ System.out.println("Error Code ="+e.getErrorCode()); System.out.println("Error message="+e.getMessage()); } catch(Exception e){ e.printStackTrace(); } finally{ try{ //close the Statement object using the close() method if(state!=null){ state.close(); } //close the Connection object using the close() method if(conn!=null){ conn.close(); } } catch(SQLException e){ System.out.println("Error Code ="+e.getErrorCode()); System.out.println("Error message="+e.getMessage()); } } }//end of main()}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -