如何在我的JDeveloper Swing项目框架上显示Oracle数据库表?

时间:2010-07-05 08:32:00

标签: oracle jdeveloper

我想在我的应用程序上显示我的Oracle数据库表。我创建了一个新的数据库连接DBConnection1。但是我没有在我的班级中绑定DBConnection1。怎么做?

1 个答案:

答案 0 :(得分:0)

行。我解决了我的问题。

            DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
            Connection connection = DriverManager.getConnection(connStr,"scott","tiger"); 

            Connector conn = new Connector(connStr);
            Statement stmt = conn.getConnection().createStatement();                       

            ResultSet rset = stmt.executeQuery(sql); 
            ResultSetMetaData metaData = rset.getMetaData();

            int rowCount = metaData.getColumnCount();                 

            for(i=1;i<=rowCount;i++)
                headers.add(metaData.getColumnLabel(i).toString()); 


            while(rset.next()){          
                Vector tmp = new Vector();
                for(i=1;i<=rowCount;i++) {
                    tmp.add(rset.getString(i));              
                }
                lists.add(tmp);
                index++;                              

这是我的连接器类。

package client;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;


public class Connector 
{
  private String connection_string;
  private Statement stmt;
  private Connection connection;

  public Connector(String conn)
  {
      //String connection_string = "jdbc:oracle:thin:@<host>:<port>:<db name>";
      try 
      {
        connection_string = conn;

        DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());  

        connection = DriverManager.getConnection(conn,"scott","tiger");                 

      } catch(Exception f) 
      {
        f.printStackTrace();
      }

  }

  public ResultSet execute(String sql) 
  {
     try 
     {
       stmt = connection.createStatement();
       return stmt.executeQuery(sql);
     } catch (Exception f) 
     {
       f.printStackTrace();
     }    
     return null;
  }


  public void setConnection_string(String connection_string)
  {
    this.connection_string = connection_string;
  }


  public String getConnection_string()
  {
    return connection_string;
  }


  public void setStmt(Statement stmt)
  {
    this.stmt = stmt;
  }


  public Statement getStmt()
  {
    return stmt;
  }


  public void setConnection(Connection connection)
  {
    this.connection = connection;
  }


  public Connection getConnection()
  {
    return connection;
  }
}