Java连接Oralce数据库小例

时间:2016-12-19 16:10:44
【文件属性】:

文件名称:Java连接Oralce数据库小例

文件大小:2.17MB

文件格式:ZIP

更新时间:2016-12-19 16:10:44

Java 连接Oralce 数据库小例

############################################################################################### 1.DBFunctions.java ############################################################################################### 定义数据库的地址和实例名称: private final String oracleDriverName = "oracle.jdbc.driver.OracleDriver"; private final String oracleUrlToConnect = "jdbc:oracle:thin:@192.168.2.16:1521:orcl"; 定义用户名和密码: public Connection getConnection() { try { this.myConnection = DriverManager.getConnection(oracleUrlToConnect, "scott", "tiger"); ############################################################################################### 1.DlgJob.java ############################################################################################### 点击JOB按据时, 执行连接和数据库的查询语句并返回结果: public void connectToDataBase() { System.out.println("connectToDataBase"); DBFunctions dbfuns = new DBFunctions(); try { // 连接 dbfuns.getConnection(); System.out.println("Now begin to excute............."); // 查询 List rslist = new ArrayList(); ResultSet newrs = dbfuns .executeQuery("select * from emp order by empno"); try { while (newrs.next()) { String id = newrs.getString("EMPNO"); String title = newrs.getString("ENAME"); String min = newrs.getString("SAL"); String max = newrs.getString("DEPTNO");


【文件预览】:
OracleTest
----.project(386B)
----src()
--------OracleTest.java(253B)
--------DBFunctions.java(2KB)
--------DlgJob.java(2KB)
--------MainWindow.java(3KB)
----lib()
--------oracle.txt(95B)
--------classes12.jar(1.07MB)
--------ojdbc14.jar(1.12MB)
----程序说明.txt(1KB)
----.metadata()
--------.mylyn()
--------.lock(0B)
--------version.ini(26B)
--------.plugins()
--------.log(5KB)
----.classpath(342B)
----bin()
--------DBFunctions.class(3KB)
--------MainWindow.class(2KB)
--------MainWindow$1.class(621B)
--------OracleTest.class(504B)
--------DlgJob.class(4KB)

网友评论

  • 做的很不错哦,已经教会我怎么连接数据库了