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();
}
}
}
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();
}
}
}
解决方案 »
- java数值类型问题
- 关于一条简单的sql语句。。。。
- Java多线程同步问题
- 急求啊!!如何结合GUI、JDBC和网络知识与技术,设计一个在线群聊系统
- Class.forName()报告java.lang.VerifyError,why?
- 下了个Javabeans Development Kit(ZIP格式的),解压后怎么运行啊?需要设置CLASSPATH吗?在线~
- 使用java或javaw启动Java程序时怎样才能不显示dos窗口?
- 使用SOCKET,怎样自动重新连接服务器
- 各位高手,小弟現在想選學Java,是否學Java真的很有"錢途",大家都進來談談經驗??
- java分割字符串
- 请教学习java用什么书比较好呢?(开发环境jbuilder4)
- 有关java的站点!
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();
}
}
}
Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@数据库IP:1521:ORCL",数据库用户名,密码);
Statement state = conn.createStatement();
ResultSet rs = state.executeQuery(sql语句);
* 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();
}
}
“oracle.jdbc.driver.OracleDriver”,如果我的客户端(程序运行的机器)没有安装Oracle的产品,能行吗?
在连接oracle时,主要是一个url的设置,如果是jbuilder4可以用Jdbc explore发现这个url,试过可行的
如果没有,可以用thin driver