回复贴子: 回复人:skyyoung(路人甲) (2001-4-4 9:13:00) 得15分 import java.sql.*;public class connectToOracle extends java.applet.Applet { Driver driver; Connection conn = null; static String driverUsed = "oracle.jdbc.driver.OracleDriver"; static String serverAddress = "jdbc:oracle:thin:scott/[email protected]:1243:myInstance"; // jdbc:oracle:thin is the driver used // scott/tiger is user/password // www.myServer.com is the same machine from where the Applet was loaded // 1234 is the port used // myInstance is where my data is public void init(){ makeConnection(serverAddress); }
回复人:skyyoung(路人甲) (2001-4-4 9:13:00) 得15分 import java.sql.*;public class connectToOracle extends java.applet.Applet { Driver driver; Connection conn = null; static String driverUsed = "oracle.jdbc.driver.OracleDriver"; static String serverAddress = "jdbc:oracle:thin:scott/[email protected]:1243:myInstance"; // jdbc:oracle:thin is the driver used // scott/tiger is user/password // www.myServer.com is the same machine from where the Applet was loaded // 1234 is the port used // myInstance is where my data is public void init(){ makeConnection(serverAddress); }
回复人:roamer() (2001-4-4 9:22:00) 得10分 Class.forName("oracle.jdbc.driver.OracleDriver"); Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@数据库IP:1521:ORCL",数据库用户名,密码); Statement state = conn.createStatement(); ResultSet rs = state.executeQuery(sql语句); 回复人:sexpunk(妖妖) (2001-4-4 9:23:00) 得15分 好久没来过了,再给你一个oci8的,是8i带的demo:/* * This sample shows how to list all the names from the EMP table */// You need to import the java.sql package to use JDBC import java.sql.*;class Employee { public static void main (String args []) throws SQLException { // Load the Oracle JDBC driver DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver()); // Connect to the database // You can put a database name after the @ sign in the connection URL. Connection conn = DriverManager.getConnection ("jdbc:oracle:oci8:@test", "scott", "tiger"); //test是oracle实例名 // Create a Statement Statement stmt = conn.createStatement (); // Select the ENAME column from the EMP table ResultSet rset = stmt.executeQuery ("select ENAME from EMP"); // Iterate through the result and print the employee names while (rset.next ()) System.out.println (rset.getString (1)); // Close the RseultSet rset.close(); // Close the Statement stmt.close(); // Close the connection conn.close(); } } 回复人:Anth(斯安) (2001-4-10 23:56:00) 得0分 一个比较笨的问题: “oracle.jdbc.driver.OracleDriver”,如果我的客户端(程序运行的机器)没有安装Oracle的产品,能行吗?
回复人:skyyoung(路人甲) (2001-4-4 9:13:00) 得15分
import java.sql.*;public class connectToOracle extends java.applet.Applet {
Driver driver;
Connection conn = null;
static String driverUsed =
"oracle.jdbc.driver.OracleDriver";
static String serverAddress =
"jdbc:oracle:thin:scott/[email protected]:1243:myInstance";
// jdbc:oracle:thin is the driver used
// scott/tiger is user/password
// www.myServer.com is the same machine from where the Applet was loaded
// 1234 is the port used
// myInstance is where my data is public void init(){
makeConnection(serverAddress);
}
public void makeConnection(String svr) {
try {
System.out.println("Loading ... " + driverUsed);
driver =
(Driver)Class.forName(driverUsed).newInstance();
System.out.println("Connecting ... " + svr);
conn =
DriverManager.getConnection(svr);
System.out.println("Ready.");
}
catch (Exception e) {
e.printStackTrace();
}
}
}
回复人:skyyoung(路人甲) (2001-4-4 9:13:00) 得15分
import java.sql.*;public class connectToOracle extends java.applet.Applet {
Driver driver;
Connection conn = null;
static String driverUsed =
"oracle.jdbc.driver.OracleDriver";
static String serverAddress =
"jdbc:oracle:thin:scott/[email protected]:1243:myInstance";
// jdbc:oracle:thin is the driver used
// scott/tiger is user/password
// www.myServer.com is the same machine from where the Applet was loaded
// 1234 is the port used
// myInstance is where my data is public void init(){
makeConnection(serverAddress);
}
public void makeConnection(String svr) {
try {
System.out.println("Loading ... " + driverUsed);
driver =
(Driver)Class.forName(driverUsed).newInstance();
System.out.println("Connecting ... " + svr);
conn =
DriverManager.getConnection(svr);
System.out.println("Ready.");
}
catch (Exception e) {
e.printStackTrace();
}
}
}
回复人:roamer() (2001-4-4 9:22:00) 得10分
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@数据库IP:1521:ORCL",数据库用户名,密码);
Statement state = conn.createStatement();
ResultSet rs = state.executeQuery(sql语句);
回复人:sexpunk(妖妖) (2001-4-4 9:23:00) 得15分
好久没来过了,再给你一个oci8的,是8i带的demo:/*
* This sample shows how to list all the names from the EMP table
*/// You need to import the java.sql package to use JDBC
import java.sql.*;class Employee
{
public static void main (String args [])
throws SQLException
{
// Load the Oracle JDBC driver
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver()); // Connect to the database
// You can put a database name after the @ sign in the connection URL.
Connection conn =
DriverManager.getConnection ("jdbc:oracle:oci8:@test", "scott", "tiger");
//test是oracle实例名
// Create a Statement
Statement stmt = conn.createStatement (); // Select the ENAME column from the EMP table
ResultSet rset = stmt.executeQuery ("select ENAME from EMP"); // Iterate through the result and print the employee names
while (rset.next ())
System.out.println (rset.getString (1)); // Close the RseultSet
rset.close(); // Close the Statement
stmt.close(); // Close the connection
conn.close();
}
}
回复人:Anth(斯安) (2001-4-10 23:56:00) 得0分
一个比较笨的问题:
“oracle.jdbc.driver.OracleDriver”,如果我的客户端(程序运行的机器)没有安装Oracle的产品,能行吗?
回复人:Zephyr_Boy(风子) (2001-4-12 23:07:00) 得5分
我想客户端没必要装oracle吧!
在连接oracle时,主要是一个url的设置,如果是jbuilder4可以用Jdbc explore发现这个url,试过可行的