java使用jdbc链接Oracle示例类分享
程序员文章站
2024-02-21 08:02:34
复制代码 代码如下:public class oraclejdbctest { str...
复制代码 代码如下:
public class oraclejdbctest
{
string driverclass = "oracle.jdbc.driver.oracledriver";
connection con;
public void init(fileinputstream fs) throws classnotfoundexception, sqlexception, filenotfoundexception, ioexception
{
properties props = new properties();
props.load(fs);
string url = props.getproperty("db.url");
string username = props.getproperty("db.user");
string password = props.getproperty("db.password");
class.forname(driverclass);
con=drivermanager.getconnection(url, username, password);
}
public void fetch() throws sqlexception, ioexception
{
preparedstatement ps = con.preparestatement("select sysdate from dual");
resultset rs = ps.executequery();
while (rs.next())
{
// do the thing you do
}
rs.close();
ps.close();
}
public static void main(string[] args)
{
oraclejdbctest test = new oraclejdbctest();
test.init();
test.fetch();
}
}
上一篇: 针对浏览器隐藏CSS
下一篇: mysql常用命令行操作语句