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

📄 jdbcapplet.java

📁 一个applet与oracle进行连接的例子(大家知道applet与数据库是比较难通讯的
💻 JAVA
字号:
/* * This sample applet just selects * from the database */// Import the JDBC classesimport java.sql.*;// Import the java classes used in appletsimport java.awt.*;import java.io.*;import java.util.*;public class JdbcApplet extends java.applet.Applet{  // The driver to load  static final String driver_class = "oracle.jdbc.driver.OracleDriver";  // The connect string: naturally not the real one   static final String connect_string =                  "jdbc:oracle:thin:user/password@hostname.zib.de:1521:orcl";   // The query we will execute  static final String query = "select 'Hello JDBC: ' || sysdate from dual";    // The button to push for executing the query  Button execute_button;  // The place where to dump the query result  TextArea output;  // The connection to the database  Connection conn;  // Create the User Interface  public void init ()  {    this.setLayout (new BorderLayout ());    Panel p = new Panel ();    p.setLayout (new FlowLayout (FlowLayout.LEFT));    execute_button = new Button ("Execute");    p.add (execute_button);    this.add ("North", p);    output = new TextArea (10, 60);    this.add ("Center", output);  }  // Do the work  public boolean action (Event ev, Object arg)  {    if (ev.target == execute_button)    {      try      {	// Clear the output area	output.setText ("");	// See if we need to open the connection to the database	if (conn == null)	{	  // Load the JDBC driver	  output.appendText ("Loading JDBC driver " + driver_class + "\n");	  Class.forName (driver_class);	  // Connect to the databse	  output.appendText ("Connecting to " + connect_string + "\n");          netscape.security.PrivilegeManager.enablePrivilege("UniversalConnect");	  conn = DriverManager.getConnection (connect_string);	  output.appendText ("Connected\n");	}	// Create a statement	Statement stmt = conn.createStatement ();	// Execute the query	ResultSet rset = stmt.executeQuery (query);	// Dump the result	while (rset.next ())	  output.appendText (rset.getString (1) + "\n");        output.appendText ("And now emps: \n");        // Create a Statement        stmt = conn.createStatement ();        // Select * from emp         rset = stmt.executeQuery ("select * from emp");        // Iterate through the result and print all rows         while (rset.next ()) {           output.appendText(rset.getString (1) + ", " + rset.getString (2) +  ", " + rset.getString (3) + ", " + rset.getString (4) + ", " + rset.getString (5));           output.appendText("\n");        }      }      catch (Exception e)      {	// Oops	output.appendText (e.getMessage () + "\n");      }      return true;    }    else      return false;  }}

⌨️ 快捷键说明

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