boracle数据库服务器:172.16.1.2,数据库实例:labora
我的数据库驱动器放在目录:E:\OracleJdbc
系统环境变量中的classpath中加入数据库驱动器值:
E:\OracleJdbc\classes12.zip;E:\OracleJdbc\classes111.zip;E:\OracleJdbc\jndi.zip;
E:\OracleJdbc\jta.zip;E:\OracleJdbc\nls_charset12.zip1.applet/*
* This sample applet just selects 'Hello World' and the date from the database
*/// Import the JDBC classes
import java.sql.*;// Import the java classes used in applets
import java.awt.*;
import java.io.*;
import java.util.*;public class JdbcApplet extends java.applet.Applet
{ // The connect string
static final String connect_string =
"jdbc:oracle:thin:@172.16.1.2:1521:labora","scott","tiger"; // This is the kind of string you would use if going through the
// Oracle 8 connection manager which lets you run the database on a
// different host than the Web Server. See the on-line documentation
// for more information.
// static final String connect_string = "jdbc:oracle:thin:scott/tiger@(description=(address_list=(address=(protocol=tcp)(host=dlsun511)(port=1610))(address=(protocol=tcp)(host=pkrishna-pc2)(port=1521)))(source_route=yes)(connect_data=(sid=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 ("Hello JDBC");
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
{ // See if we need to open the connection to the database
if (conn == null)
{
// Load the JDBC driver
DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver()); // Connect to the databse
output.appendText ("Connecting to " + connect_string + "\n");
conn = DriverManager.getConnection (connect_string);
output.appendText ("Connected\n");
} // Create a statement
Statement stmt = conn.createStatement (); // Execute the query
output.appendText ("Executing query " + query + "\n");
ResultSet rset = stmt.executeQuery (query); // Dump the result
while (rset.next ())
output.appendText (rset.getString (1) + "\n"); // We're done
output.appendText ("done.\n");
}
catch (Exception e)
{
// Oops
output.appendText (e.getMessage () + "\n");
}
return true;
}
else
return false;
}
}2.调用该applet的html<html>
<head>
<title>JDBC applet</title>
</head>
<body><h1>JDBC applet</h1>This page contains an example of an applet that uses the Thin JDBC
driver to connect to Oracle.<p>The source code for the applet is in <a
href="JdbcApplet.java">JdbcApplet.java</a>. Please check carefully
the driver class name and the connect string in the code.<p>The Applet tag in this file contains a CODEBASE entry that must be set
to point to a directory containing the Java classes from the Thin JDBC
distribution *and* the compiled JdbcApplet.class.<p>As distributed it will *not* work because the classes111.zip are not
in this directory.<p><hr>
<applet codebase="." archive="classes111.zip"
code="JdbcApplet" width=500 height=200>
</applet>
<hr>
我的数据库驱动器放在目录:E:\OracleJdbc
系统环境变量中的classpath中加入数据库驱动器值:
E:\OracleJdbc\classes12.zip;E:\OracleJdbc\classes111.zip;E:\OracleJdbc\jndi.zip;
E:\OracleJdbc\jta.zip;E:\OracleJdbc\nls_charset12.zip1.applet/*
* This sample applet just selects 'Hello World' and the date from the database
*/// Import the JDBC classes
import java.sql.*;// Import the java classes used in applets
import java.awt.*;
import java.io.*;
import java.util.*;public class JdbcApplet extends java.applet.Applet
{ // The connect string
static final String connect_string =
"jdbc:oracle:thin:@172.16.1.2:1521:labora","scott","tiger"; // This is the kind of string you would use if going through the
// Oracle 8 connection manager which lets you run the database on a
// different host than the Web Server. See the on-line documentation
// for more information.
// static final String connect_string = "jdbc:oracle:thin:scott/tiger@(description=(address_list=(address=(protocol=tcp)(host=dlsun511)(port=1610))(address=(protocol=tcp)(host=pkrishna-pc2)(port=1521)))(source_route=yes)(connect_data=(sid=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 ("Hello JDBC");
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
{ // See if we need to open the connection to the database
if (conn == null)
{
// Load the JDBC driver
DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver()); // Connect to the databse
output.appendText ("Connecting to " + connect_string + "\n");
conn = DriverManager.getConnection (connect_string);
output.appendText ("Connected\n");
} // Create a statement
Statement stmt = conn.createStatement (); // Execute the query
output.appendText ("Executing query " + query + "\n");
ResultSet rset = stmt.executeQuery (query); // Dump the result
while (rset.next ())
output.appendText (rset.getString (1) + "\n"); // We're done
output.appendText ("done.\n");
}
catch (Exception e)
{
// Oops
output.appendText (e.getMessage () + "\n");
}
return true;
}
else
return false;
}
}2.调用该applet的html<html>
<head>
<title>JDBC applet</title>
</head>
<body><h1>JDBC applet</h1>This page contains an example of an applet that uses the Thin JDBC
driver to connect to Oracle.<p>The source code for the applet is in <a
href="JdbcApplet.java">JdbcApplet.java</a>. Please check carefully
the driver class name and the connect string in the code.<p>The Applet tag in this file contains a CODEBASE entry that must be set
to point to a directory containing the Java classes from the Thin JDBC
distribution *and* the compiled JdbcApplet.class.<p>As distributed it will *not* work because the classes111.zip are not
in this directory.<p><hr>
<applet codebase="." archive="classes111.zip"
code="JdbcApplet" width=500 height=200>
</applet>
<hr>
Connecting to jdbc:oracle:thin:scott/tiger@DB:1521:ora7
No suitable driver这说明:没有找到驱动程序即使如上述:As distributed it will *not* work because the classes111.zip are not
in this directory.<p>也不行。当然在本机运行适当让可以:(2001-05-28 20:47:58) Oracle
Loading JDBC driver oracle.jdbc.driver.OracleDriver
Connecting to jdbc:oracle:thin:scott/tiger@DB:1521:ora7
Connected
Executing query select 'Hello JDBC: ' || sysdate from dual
Hello JDBC: 28-MAY-01
done.问题是:但客户端如何下载Thin 驱动那??????
Connecting to jdbc:oracle:thin:scott/tiger@DB:1521:ora7
No suitable driver <<<<------------------扑捉到错误(没有找到驱动)已经尝试的方法:1。archive法:(classes111.jar为内涵驱动和Applet的archive)<APPLET CODE = "gsp.Client" CODEBASE = "." archive="classes111.jar" WIDTH = 400 HEIGHT = 400 ALIGN = middle NAME = "TestApplet" >
</APPLET>2。在同一目录下有: Html,Applet,oracle(我把它解压开了)。。