在java 中怎样调用oracle数据库中的数据
发布网友
发布时间:2022-04-22 11:32
我来回答
共2个回答
热心网友
时间:2022-04-09 23:55
public class Text {
public static final void main(String args[]){
Connection con = null;
try {
//1,加载驱动程序
Class.forName("oracle.jdbc.driver.OracleDriver");
//2,连接字符串
String s = "jdbc:oracle:thin:@localhost:1521:shitou";
//3,获得数据库连接
con = DriverManager.getConnection(s,"system","abc");
//4,获得语句对象
Statement stat = con.createStatement();
//5,执行sql
ResultSet rs = stat.executeQuery("select * from comp");
热心网友
时间:2022-04-10 01:13
package com.hyq.src;
public class TestProcereTWO {
public TestProcereTWO() {
}
public static void main(String[] args ){
String driver = "oracle.jdbc.driver.OracleDriver";
String strUrl = "jdbcracle:thin127.0.0.1:1521:hyq";
Statement stmt = null;
ResultSet rs = null;
Connection conn = null;
try {
Class.forName(driver);
conn = DriverManager.getConnection(strUrl, " hyq ", " hyq ");
CallableStatement proc = null;
proc = conn.prepareCall("{ call HYQ.TESTB(?,?) }");
proc.setString(1, "100");
proc.registerOutParameter(2, Types.VARCHAR);
proc.execute();
String testPrint = proc.getString(2);
System.out.println("=testPrint=is="+testPrint);
}
catch (SQLException ex2) {
ex2.printStackTrace();
}
catch (Exception ex2) {
ex2.printStackTrace();
}
finally{
try {
if(rs != null){
rs.close();
if(stmt!=null){
stmt.close();
}
if(conn!=null){
conn.close();
}
}
}
catch (SQLException ex1) {
}
}
}
}
}