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

📄 first.java~4~

📁 基于java的学生信息管理系统的开发与应用
💻 JAVA~4~
字号:
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"          );      //      //the next() method      result.next();      //retrieve the user from the row in the Resultset using      //the getString() 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 + -