JAR package: class12.jar
package com.util;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class DBConnection {
private String drivername;
private String dburl;
private String username;
private String password;
public Connection getConnection() {
try {
Class.forName(drivername);
return DriverManager.getConnection(dburl, username, password);
} catch (ClassNotFoundException e) {
System.out.println(e.getMessage());
e.printStackTrace();
} catch (SQLException e) {
System.out.println(e.getMessage());
e.printStackTrace();
}
return null;
}
public String getDrivername() {
return drivername;
}
public void setDrivername(String drivername) {
this.drivername = drivername;
}
public String getDburl() {
return dburl;
}
public void setDburl(String dburl) {
this.dburl = dburl;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
package com.util;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class DBDemon {
/**
* @param args
*/
public static void main(String[] args) {
DBConnection dbdemon = new DBConnection();
dbdemon.setDrivername("oracle.jdbc.driver.OracleDriver");
dbdemon.setDburl("jdbc:oracle:thin:@host:port:sid");
dbdemon.setUsername("username");
dbdemon.setPassword("password");
Connection conn = dbdemon.getConnection();
ResultSet rs = null;
try {
Statement stmt = conn.createStatement();
String sql = "select * from sc_processing_queue";
rs = stmt.executeQuery(sql);
while (rs.next()) {
System.out.println(rs.getInt(1));
System.out.println(rs.getInt(2));
System.out.println(rs.getString(3));
System.out.println(rs.getString(4));
System.out.println(rs.getString(5));
System.out.println(rs.getDate(6));
System.out.println(rs.getDate(7));
}
} catch (SQLException e) {
System.out.println(e.getMessage());
} finally {
try {
rs.close();
conn.close();
} catch (SQLException e) {
System.out.println(e.getMessage());
}
}
}
}
分享到:
相关推荐
本示例代码"example(JDBC).rar_jdbc_oracle"主要展示了如何使用JDBC API与Oracle数据库进行交互,包括基本的CRUD(创建、读取、更新、删除)操作。下面我们将深入探讨这些知识点: 1. JDBC接口: JDBC是Java SDK的...
Example: jdbc:oracle:thin:@localhost:1521:orcl 这种格式是最简单也是用得最多的 你的oracle的sid可以通过一下指令获得: sqlplus / as sysdba select value from v$parameter where name='instance_name'; ...
# Another example of the URL would be jdbc:oracle:thin:@//ip:port/database. For more information, please go to the JDBC driver docs connection-url=jdbc:oracle:thin://ip:port/database connection-user=...
注意,这里的URL格式是`jdbc:oracle:thin`,这表明我们正在使用Thin Driver。在实际应用中,你需要替换`<数据库服务器>`, `<端口号>` 和 `<服务名>` 为实际的Oracle数据库信息。 总的来说,这个"oracle8驱动包.zip...
1. **JDBC驱动**:Oracle提供了几种不同版本的JDBC驱动,如 Thin 驱动、 Thick 驱动和 Jdbc-ODBC 桥接。其中,Thin驱动是最常用的一种,因为它无需Oracle客户端即可直接连接到数据库,降低了系统需求。 2. **连接...
jdbc:oracle:thin:@//dbserver.example.com:1521/ORCL ``` 连接字符串还可以包含其他参数,如用户认证信息: ``` jdbc:oracle:thin:@//dbserver.example.com:1521/ORCL 用户名/密码 ``` 为了安全起见,通常不建议...
Oracle JDBC驱动,也称为Oracle Thin Driver,是一个纯Java实现的驱动,无需本地Oracle客户端即可运行。`ojdbc6.jar`文件包含了Oracle JDBC驱动的所有必要类和资源,用于建立Java应用程序与Oracle数据库之间的网络...
spring.datasource.url=jdbc:oracle:thin:@localhost:1521:ORCL spring.datasource.username=root spring.datasource.password=password spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver ...
String url = "jdbc:oracle:thin:@hostname:port/service_name"; String username = "your_username"; String password = "your_password"; try { Connection conn = DriverManager.getConnection(url, ...
其中,Thin驱动(也称为Oracle JDBC Thin Driver)是完全基于Java的Type 4驱动,直接与Oracle数据库通信,无需Oracle客户端软件。配置时,需要指定driver类(如oracle.jdbc.driver.OracleDriver)和连接URL(如jdbc:...
接下来,Oracle JDBC驱动,通常称为Oracle Thin Driver,是一个纯Java实现的驱动,无需本地Oracle客户端。Oracle_Driver.rar中包含的JAR文件(如ojdbc.jar)也需要被加入到项目类路径。Oracle的JDBC驱动允许Java应用...
通常,我们使用 Thin 驱动,其对应的类是oracle.jdbc.driver.OracleDriver。以下是使用Oracle JDBC Thin驱动的示例: ```java import java.sql.Connection; import java.sql.DriverManager; public class ...
"jdbc:oracle:thin:@//dbserver.example.com:1521/orcl.example.com", "username", "password"); ``` 6. **测试连接**: 使用SQL*Plus或其他工具,测试连接是否成功。在命令行中输入`sqlplus username/password@...
你需要在`<Context>`标签内添加以下代码来定义一个名为`jdbc/myoracle`的数据源,使用`thin`驱动连接到本地的Oracle数据库,用户为`scott`,密码为`tiger`,数据库服务标识符(SID)为`mysid`: ```xml ...
url="jdbc:oracle:thin:@localhost:1521:XE" username="mss" password="mss" maxActive="50" maxIdle="2" maxWait="10000"/> ``` 这里定义了一个具体的`DataSource`实例,并指定了数据库的URL、用户名、...
<property name="jdbcUrl" value="jdbc:oracle:thin:@localhost:1521:ORCL"/> <property name="jdbcUsername" value="username"/> ``` `jdbcConnection`元素用于设置JDBC连接属性,而`javaModelGenerator`元素...
spring.datasource.url=jdbc:oracle:thin:@//hostname:port/service_name spring.datasource.username=your_username spring.datasource.password=your_password spring.datasource.driver-class-name=oracle.jdbc....
<property name="url" value="jdbc:oracle:thin:@localhost:1521:ORCL"/> ``` 3. **创建Mapper接口和XML文件**: 在MyBatis中,你需要定义一个Mapper接口,例如`TestMapper`,并编写对应的XML文件。...
spring.datasource.url=jdbc:oracle:thin:@//hostname:port/service_name spring.datasource.username=your_username spring.datasource.password=your_password spring.datasource.driver-class-name=oracle.jdbc....
String url = "jdbc:oracle:thin:@ip:1521:database_name"; Connection conn = DriverManager.getConnection(url, "username", "password"); Statement stmt = conn.createStatement(); ResultSet rs = stmt....