当前位置:首页 » 编程语言 » java插入oracle

java插入oracle

发布时间: 2023-03-08 10:33:06

⑴ 怎么用java连接oracle数据库,需要详细解释

1)首先你要有java连接oracle数据库的驱动类,下载好后导入到工程里

2)代码:
import java.sql.*;

public class JDBCTest {

/**
* @param args
* @throws ClassNotFoundException
*/
public static void main(String[] args)
throws ClassNotFoundException, SQLException{
//1.准备参数
String ip = "192.168.0.26";
String sid = "tarena";
String port = "1521";
String dbUser = "openlab";
String dbPassword = "open123";
String driver
= "oracle.jdbc.driver.OracleDriver";

//2.构造驱动实例
Class.forName(driver);

//3.创建连接
//连接字符串是固定的形式,oracle的形式:
String url
= "jdbc:oracle:thin:@"
+ ip + ":" + port + ":" + sid;
Connection conn
= DriverManager.getConnection
(url, dbUser, dbPassword);
//4.执行SQL语句
String sql = "select id, password, name from user_sd1104 " +
"where id = 1001 and password = '1234'";
Statement stmt = conn.createStatement();
ResultSet rs
= stmt.executeQuery(sql);//执行sql语句
while(rs.next()){
int id = rs.getInt(1);
String pwd = rs.getString(2);
String name = rs.getString(3);
System.out.println("welcome," + name);
}
rs.close();
stmt.close();
conn.close();
}

}

热点内容
win7本地服务密码是什么 发布:2024-11-06 23:37:45 浏览:677
关闭窗口java 发布:2024-11-06 23:37:44 浏览:31
php计算字符串长度的函数 发布:2024-11-06 23:35:05 浏览:353
小米自制脚本 发布:2024-11-06 23:34:18 浏览:314
qq访问问题 发布:2024-11-06 23:29:20 浏览:648
手机邮件接收服务器怎么设置 发布:2024-11-06 23:23:35 浏览:128
c语言循环例题 发布:2024-11-06 23:05:01 浏览:332
外星人m15r6选哪个配置 发布:2024-11-06 23:03:58 浏览:999
linuxmysql数据库安装 发布:2024-11-06 23:01:28 浏览:117
压缩器能干嘛 发布:2024-11-06 23:01:16 浏览:464