ConnOracle.java
资源名称:examasp.rar [点击查看]
上传用户:hjt198082
上传日期:2015-04-16
资源大小:95k
文件大小:2k
源码类别:
MySQL数据库
开发平台:
Java
- package test;
- import java.io.PrintStream;
- import java.sql.*;
- public class ConnOracle
- {
- //String serverName;
- String sDBDriver;
- String sConnStr;
- Connection connect;
- ResultSet rs;
- public ConnOracle()
- {
- //serverName = "localhost";
- //sDBDriver = "oracle.jdbc.driver.OracleDriver";
- //sConnStr = "jdbc:oracle:thin:@" + serverName + ":1521:ora9";
- sDBDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
- sConnStr = "jdbc:odbc:aaa";
- connect = null;
- rs = null;
- try
- {
- Class.forName(sDBDriver);
- }
- catch(ClassNotFoundException classnotfoundexception)
- {
- System.err.println(classnotfoundexception.getMessage());
- }
- }
- public ResultSet executeQuery(String s)
- {
- try
- {
- connect = DriverManager.getConnection(sConnStr, "abc", "abc");
- Statement statement = connect.createStatement(1004, 1007);
- //1007:ResultSet.CONCUR_READ_ONLY------resultSetType
- //1004:ResultSet.TYPE_SCROLL_INSENSITIVE------concurrency type
- rs = statement.executeQuery(s);
- }
- catch(SQLException sqlexception)
- {
- System.err.println(sqlexception.getMessage());
- }
- return rs;
- }
- public int executeUpdate(String s)
- {
- int i = 0;
- try
- {
- connect = DriverManager.getConnection(sConnStr, "abc", "abc");
- Statement statement = connect.createStatement(1004, 1007);
- i = statement.executeUpdate(s);
- }
- catch(SQLException sqlexception)
- {
- System.err.println(sqlexception.getMessage());
- }
- return i;
- }
- }