// // ThinJdbcTesterApplet.java // 2001/01/07 // import java.sql.*; import java.awt.*; //import javax.swing.*; import java.awt.event.*; import java.applet.Applet; //import java.io.*; public class ThinJdbcTesterApplet extends Applet { private Label laba; class ConActionListener implements ActionListener { private ThinJdbcTesterApplet t; public ConActionListener(ThinJdbcTesterApplet t){ this.t = t; } public void actionPerformed(ActionEvent e){ this.t.connectToDB(); } } public void init(){ this.setSize(new Dimension(100, 50)); this.laba = new Label("むむむ"); Button cmda = new Button("接続"); this.setLayout(new BorderLayout()); this.add(this.laba, BorderLayout.NORTH); this.add(cmda, BorderLayout.SOUTH); cmda.addActionListener(new ConActionListener(this)); } public void connectToDB(){ String result = ""; try { // Oracle JDBC driverをロードします。 DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver()); Connection conn = DriverManager.getConnection( "jdbc:oracle:thin:xqte/xqte@ushi2:1521:orcl", "XQTE", "XQTE"); // SQL文(DML文)を作ります。 Statement stmt = conn.createStatement (); // SELECT文の場合はexecuteQuery()を実行します。 ResultSet rset = stmt.executeQuery ("select 'Hello World' from dual"); while (rset.next ()) result += rset.getString(1); // 結果セットを解放 rset.close(); // SQL文を解放 stmt.close(); // データベースから切断して、完了。 conn.close(); } catch(SQLException ex){ result = "Ootto! " + ex.getMessage(); ex.printStackTrace(); } this.laba.setText(result); } public static void main(String args[]){ Frame f = new Frame("サンプル"); f.setSize(100, 50); ThinJdbcTesterApplet my = new ThinJdbcTesterApplet(); my.init(); f.add(my); f.show(); } } // end.