Giter Club home page Giter Club logo

Comments (3)

bjeffrie avatar bjeffrie commented on August 15, 2024

So you want to use multiple user/pw with one SQLDev Connection? Do I understand correctly or would multiple (java.sql) connections via the same credentials work?

What problem is the extension meant to solve? Throwing script(s) at a bunch of connections would seem more a scripting thing you could do with sqlcl to me but I don't know your context.

Note that SQLDev Connections are identified by {store name}%{connection name} and define a {user}+[{password}+]{connection driver info e.g. host,port,sid/service[,role], etc. for Oracle DB}

That said, there are utility functions for getting unique (java.sql) connections for a given SQLDeveloper connection and also for creating a SQLDev Connection for a new user/pw based on an existing one. E.g.,

  for (String qualifiedConnectionName : ConnectionResolver.getConnectionNames()) {
    // Get shared connection for qualified name (this is the one SQLDeveloper uses for the navigator and displays)
    java.sql.Connection sharedConn = ConnectionResolver.getConnection(qualifiedConnectionName);
    
    // Get unique (unnamed) connection using credentials from qualifiedConnectionName 
    java.sql.Connection uniqueConn = ConnectionResolver.getUniqueConnection(qualifiedConnectionName);
    
    // Get new connection for name/pw using connection driver info from qualifiedConnectionName
    String folderName = null; // Will use "Connections based on " + qualifiedConnectionName if null
    String username = "someUser"; // Must be unique as it will be used as the connection name
    String password = "somePassword";
    ConnectionUtils.addNewConnectionBasedOn(folderName, qualifiedConnectionName, username, password);
    String newConnQualifiedName = ConnectionResolver.getQualifiedConnectionName(username);
    java.sql.Connection newConn = ConnectionResolver.getConnection(newConnQualifiedName);
    
    java.sql.Connection myConn = newConn; // or uniqueConn
    String displayName = ConnectionResolver.getConnectionName(myConn); // null for uniqueConn(s)
    
    // do stuff ...
    // See if one of the DBUtil.getInstance(myConn).execute... methods work for you - it handles locking/error reporting
  
   // if using newConn, close and remove sqldev connection  
    Connections.close(newConnQualifiedName);

(*%%$ I'm going to have to add some way for extensions to programmatically delete the connection to sqldev itself. (19.4 hopefully)

from oracle-db-examples.

bjeffrie avatar bjeffrie commented on August 15, 2024

Added utility functions for 19.4. Example usage creating, openening, and setting up to close(if needed)+delete the new connection when sqldeveloper exits:

Given a (fully qualified) connectionName for an existing connection

                SwingUtilities.invokeLater(() -> {
                    final String folder = "Testing";
                    final String user = "someUser"; // Must be unique as it will be used as the connection name
                    final String pw = "somePassword";
                    ConnectionUtils.addNewConnectionBasedOn(folder, connectionName, user, pw);
                    final String fqName = ConnectionUtils.getFqConnectionName(user);
                    ConnectionUtils.connect(fqName);
                    ExitCommand.addShutdownHook(new ShutdownHook() {
                        @Override
                        public boolean canShutdown() {
                            return true;
                        }
                        @Override
                        public void shutdown() {
                            ConnectionUtils.closeAndDeleteConnection(fqName);
                        }
                    });
                });

from oracle-db-examples.

bjeffrie avatar bjeffrie commented on August 15, 2024

No response to the answer in a month. Assuming it is OK or user no longer cares. Closing.

from oracle-db-examples.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.