ConnOracle.java
上传用户:hjt198082
上传日期:2015-04-16
资源大小:95k
文件大小:2k
源码类别:

MySQL数据库

开发平台:

Java

  1. package test;
  2. import java.io.PrintStream;
  3. import java.sql.*;
  4. public class ConnOracle
  5. {
  6.     //String serverName;
  7.     String sDBDriver;
  8.     String sConnStr;
  9.     Connection connect;
  10.     ResultSet rs;
  11.     public ConnOracle()
  12.     {
  13.         //serverName = "localhost";
  14.         //sDBDriver = "oracle.jdbc.driver.OracleDriver";
  15.         //sConnStr = "jdbc:oracle:thin:@" + serverName + ":1521:ora9";
  16.         sDBDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
  17.         sConnStr = "jdbc:odbc:aaa";
  18.         connect = null;
  19.         rs = null;
  20.         try
  21.         {
  22.             Class.forName(sDBDriver);
  23.         }
  24.         catch(ClassNotFoundException classnotfoundexception)
  25.         {
  26.             System.err.println(classnotfoundexception.getMessage());
  27.         }
  28.     }
  29.     public ResultSet executeQuery(String s)
  30.     {
  31.         try
  32.         {
  33.             connect = DriverManager.getConnection(sConnStr, "abc", "abc");
  34.             Statement statement = connect.createStatement(1004, 1007);
  35.             //1007:ResultSet.CONCUR_READ_ONLY------resultSetType
  36.             //1004:ResultSet.TYPE_SCROLL_INSENSITIVE------concurrency type
  37.             rs = statement.executeQuery(s);
  38.         }
  39.         catch(SQLException sqlexception)
  40.         {
  41.             System.err.println(sqlexception.getMessage());
  42.         }
  43.         return rs;
  44.     }
  45.     public int executeUpdate(String s)
  46.     {
  47.         int i = 0;
  48.         try
  49.         {
  50.             connect = DriverManager.getConnection(sConnStr, "abc", "abc");
  51.             Statement statement = connect.createStatement(1004, 1007);
  52.             i = statement.executeUpdate(s);
  53.         }
  54.         catch(SQLException sqlexception)
  55.         {
  56.             System.err.println(sqlexception.getMessage());
  57.         }
  58.         return i;
  59.     }
  60. }