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

发布于 2024-09-08 08:30:06 字数 93 浏览 4 评论 0原文

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

I want to show my Oracle DB tables on my application. I create a new database connection DBConnection1. But I don't bind DBConnection1 in my class. How to do it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

放血 2024-09-15 08:30:06

好的。我解决我的问题。

            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;
  }
}

OK. I solve my question.

            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++;                              

Here is the my connector class.

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;
  }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文