码迷,mamicode.com
首页 > 数据库 > 详细

java连接oracle

时间:2014-12-17 14:18:25      阅读:191      评论:0      收藏:0      [点我收藏+]

标签:ar   io   os   使用   sp   for   java   on   文件   

//使用java操作oracle数据库的例子
//文件名:testora.java
import java.sql.*;
public class testora {
    public static void main(String args[]) {
        try {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); 
            Connection conn = DriverManager.getConnection("jdbc:odbc:myorc80","username","password");
            Statement sm=conn.createStatement();
            ResultSet rs=sm.executeQuery("select * from emp");
            
            System.out.println("编号"+"  "+"姓名"+"  "+"职位"+"  "+"领导编号"
                +"  "+"雇佣日期"+"  "+"工资"+"  "+"奖金"+"  "+"部门编号");
            while(rs.next()) {
                System.out.print(rs.getString(1)+"  ");
                System.out.print(rs.getString(2)+"  ");
                System.out.print(rs.getString(3)+"  ");
                System.out.print(rs.getString(4)+"  ");
                System.out.print(rs.getString(5)+"  ");
                System.out.print(rs.getString(6)+"  ");
                System.out.print(rs.getString(7)+"  ");
                System.out.println(rs.getString(8));
            }
            conn.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

java连接oracle

标签:ar   io   os   使用   sp   for   java   on   文件   

原文地址:http://www.cnblogs.com/gorechen/p/4169105.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!