jdbc-odbc连接数据库

类别:Java 点击:0 评论:0 推荐:

/*jdbc-odbc连接数据库*/ 

package dbJavaBean;

import java.sql.*;

public class Opendb {

 String sDBDriver="sun.jdbc.odbc.JdbcOdbcDriver";
 String sConnStr="jdbc:odbc:one";
 Connection conn=null;
 ResultSet rs=null;

 public Opendb() {
  try {
   Class.forName(sDBDriver);
  }
  catch(java.lang.ClassNotFoundException e){
   System.err.print(e.getMessage());
  }
 }

public ResultSet executeQuery(String sql){
  rs=null;
  try{
   conn=DriverManager.getConnection(sConnStr);
   Statement stmt=conn.createStatement();
   rs=stmt.executeQuery(sql);
  }
  catch(SQLException ex){
   System.err.print(ex.getMessage());
  }
  return rs;
 }
}

本文地址:http://com.8s8s.com/it/it18109.htm