Multiple database access

Hi there!
I'm having problems with connection to my databases. The idea is:
-step 1. Check if a number exists in database A (connect A-->query-->close A)
-if the number does exist, do nothing
-step 2 else, open database B and,
-step 3 copy the record of the particular number to database A (connect B-->query-->close B --> connect A --> query --> close A)
Now the problem is that somehow the database url stays the same (URL of db A), and so I cannot connect to database B.
This is my db connection method, which I call from another class. As you can see, i've put up some println's to see where the error pop's up, but it makes absolutely no sense.
public void openConnection(String database, String username, String password)
               try     {
                    String url = new String("jdbc:mysql://" + database);
                    Class.forName("com.mysql.jdbc.Driver");
                    System.out.println("Opening database "+url +" with credentials: "+username+ " AND password: "+password);
                    connection = DriverManager.getConnection(url, username, password);
                    System.out.println("Connection opened");
               } catch( ClassNotFoundException e) {
               System.out.println("JDBC Error:");
               e.printStackTrace();
               catch ( java.sql.SQLException e ) {
               System.err.println("SQL Exception:");
               e.printStackTrace();
     }Now the following output/error occurs:
(step 1)Opening database jdbc:mysql://localhost/sms with credentials: blaat AND password: blaat
Connection opened(step 2)Opening database jdbc:mysql://otherhost/users with credentials: blaat1 AND password: blaat1
SQL Exception:
java.sql.SQLException: Access denied for user 'blaat1'@'localhost' (using password: YES)(step 3)Opening database jdbc:mysql://localhost/sms with credentials: blaat AND password: blaat
Connection openedAnyone?!

JKNOWS wrote:
Then I call openconnection with database address "otherhost" (which it DOES display in the System.out.prinln) but the connection fails, and when you look in the errorlog you can see that it still tried to connect to "localhost"..?!??!As a guess you are reading more into that error message that what it says.
The error can only occur if it is in fact connecting to a database. So at a minimum if you stopped the local server then you can insure that it is not doing that. But as a guess I would suppose 'localhost' in the error message is meaningless. As noted in the previous post it is just telling you that the log in failed.

Similar Messages

  • Multiple Database access in a single transaction

    Hello All,
    I have read in a book which states that "according to J2ee Specification,a single transaction(an EJB method for example) may not be provided access to multiple JDBC resource providers.."
    Does it mean that i cannot access multiple databases from different vendors in a single EJB transaction??
    Any help is very much appreciated
    Thanks

    Hello Sebastien,
    Thanks for your response!!!
    Let me make it bit more clear.In deploymewnt descriptor,we define jndi name for any resource and do a lookup on that resource from the code.
    Let us consider that resource as JDBC data source for our discussion.usually you define any jdbc data source under a JDBC resource provider.
    So my question is,in a single transaction can you access multiple data sources defines under multiple JDBC resource providers.
    Ex:A datasource "x "defined under resource provider "A"[say DB2 jbdc provider] and a datasource "y" defined under respurce provider "B"[say mysql jdbc provider].
    Thanks

  • How to access multiple database present in single instance

    Hi Team,
    In oracle 11.2, can there be multiple databases in an instance???  In one of our environment, I could see multiple databases in an instance. Could you please help me in giving the data dictionary or query to access those databases?
    Actually, querying v$database, I could see only one database which is same as instance name. But in inventory, there are multiple database in an instance?
    I am still not exactly clear about this. Can someone help me with this?
    Thanks!
    Vidhya

    In Oracle one instance manages one (1) database. A database consists of multiple *schemas*.
    Other vendors erroneously call a schema 'database'.
    So, no, you didn't see multiple databases.
    There is also one datadictionary, consisting of a set of views.
    All views beginning with dba_  list the entire database, all schemas.
    All views beginning with all_ list the objects you have access to.
    All views beginning with user_ list your own objects.
    The view DICT show you the contents of the datadictionary.
    Oracle also has online documentation at http://docs.oracle.com
    From your question it is clear you should read the document called the 'Oracle Concepts Manual'.
    You can find all documentation for 11gR2 here Oracle Database Online Documentation 11g Release 2 (11.2)
    Too many people here don't make any effort to read it. This is probably the reason why you got no response.
    Sybrand Bakker
    Senior Oracle DBA

  • Using Single Datasource to Access Multiple Databases

    Hi,
    We would like to know the pros and cons of accessing multiple
    databases through a single datasource, versus accessing each
    database through its own datasource. Our environment includes
    multiple web servers w/ the latest version of ColdFusion MX 7,
    clustered through a load balancer. Each web server has 800+ dsns
    pointing to different SQL databases on the same SQL server. We have
    noticed that the ColdFusion administrator is taking a long time to
    display or verify all datasources and sometimes it even times out.
    Another problem is that sometimes the neo-query file gets corrupted
    (for unknown reasons) which results in the deletion of one, or
    more, or all datasources on the web server.
    Because of the issues above we are researching the
    possibility of removing most of the datasources, and then accessing
    each database through a single bridge datasource. In that regard we
    plan to change our queries by inserting the sql db name and user in
    front of each table in the query such as:
    <cfquery name="query" datasource="single_dsn_name">
    select * from [#dbname#].dbo.tableName
    </cfquery>
    In the example above, obviously #dbname# would be a variable
    that will hold the name of the requested database. The code above
    would similarly apply to queries using, update, insert and join
    words.
    Are there any limitations or negatives from scalability,
    performance, and reliability perspective in implementing the above
    scenario versus having one datasource for each database.
    Also, if there is a better way of accomplishing this, we
    would love to hear about it.

    Here is my opinion, because I work with both schemas. The
    main advantage to use one datasource for all DBs in a SQL Server is
    the simplicity of administration.
    But the main disadvantage is security, because you are using
    a single user to access all DB in a server, you don't have
    isolation, and a user that knows your schema can access data of
    other DBs that he sould not be authorized.
    Another issue is is a user must access 2 differents DB with
    different permissions (a DB only read and the other read/write),
    you'll have to create another datasource, user, etc for it.
    But the decision depends in the enviroment. If you are a
    hosting company, I would use 1 datasource for user or DB. If the
    servers and DBs are of the same company, I could use one datasource
    for each SQL server.
    Best regards

  • 1 user license access multiple database

    Hi all...
    I have a question :
    In SAP B1 8.8, can 1 user license (for 1 physical user) access multiple databases?
    Multiple database is created for Head Office and Branches.
    Since Finance Accounting Manager is centralized at Head Office, so the Manager must have access to multiple databases.
    Can only 1 user license applied to this Finance Accounting Manager?
    Regards,

    Hi Ingrid,
    Finance/Logistic/CRM Limited will perform as professional user license in the multiple db accessing in one server except  the functionality authorization. You must make sure that all the users that use the Finance/Logistic/CRM Limited license have the same user code in the dbs
    JimM
    <ultra - said it once>

  • Accessing Multiple Databases

    I have a requirement in which I will need to use the same classes to
    access different databases. In other words, let's say I have a Person
    class. I'd like to use the enhanced Person class to pull people from a
    SQL Server database, and an Oracle database.
    The documentation mentions that you can access multiple databases by using
    different kodo.properties files with different names. However, it doesn't
    mention using different mappings, that I can see.
    What I'm thinking I could do is extend kodo.jdbc.meta.FileMappingFactory.
    Then I could have a .mapping file for each different database. My
    extension would just need to know to access *.sqlserver.mapping or
    *.oracle.mapping for instance.
    Is this plausible? If so, any hints on extending FileMappingFactory? How
    is that guy determining the name of the mapping file? Can I simply
    override a method?
    I'm hoping this will work, so that I don't have to create a
    SQLServerPerson and an OraclePerson. Any ideas appreciated.
    Thanks,
    Steve

    Ok, in answer to my own question, I'm providing the following which I hope
    Abe or Stephen will look at, and tell me this won't break everything.
    It seems that jdbc-class-ind is only read at the base level, and thus I
    couldn't add an "indicator" for each of my subclasses. So, as I wrote
    previously, I needed a way to read my jdbc-class-ind-value in my .mapping
    file for each class. Here is the code I came up with:
    <code>
    public class MyFileMappingFactory extends FileMappingFactory {
    JDBCConfiguration myConfiguration = null;
    static Logger log = Logger.getLogger(MyFileMappingFactory.class);
    public synchronized void readMapping(ClassMetaData type,
    MappingInfoRepository repos) {
    super.readMapping(type,repos);
    try {
    String[] persistentClasses =
    myConfiguration.getPersistentClassesList();
    MappingRepository mappingRepos =
    myConfiguration.getMappingRepository ();
    for (int i=0;i<persistentClasses.length;i++) {
    String className = persistentClasses;
    try {
    Class clazz = Class.forName(className);
    ClassMapping mapping = mappingRepos.getMapping(
    clazz, clazz.getClassLoader(), true);
    mapping.addExtension(
    "jdbc-class-ind-value",
    mapping.getMappingInfo().getAttribute("jdbc-class-ind-value"));
    catch (Exception e) {
    log.error("Could not set jdbc-class-ind-value for class '" +
    className + "'.");
    catch (Exception ex) {
    public void setConfiguration(Configuration conf)
    myConfiguration = (JDBCConfiguration) conf;
    super.setConfiguration(conf);
    </code>
    I did a lot of introspection using JBuilder as well as the Javadoc to
    figure out what I needed to call. Basically, I need to have
    kodo.PersistentClasses set in my config file, and I added an attribute to
    the .mapping jdbc-class-map element. Finally, my kodo.properties has to
    point to my custom MappingFactory.
    It all seems to work, but I wanted to verify with the experts I'm not
    breaking anything. I had hoped to figure out how to put an <extension> in
    the .mapping file so that it stood out even more as being "custom code",
    but could not figure out how to read such an element.
    Steven Kouri wrote:
    I think you've answered my question, but it doesn't help my problem. I
    actually did both: I loaded the static classes in my code as well as used
    the kodo.PersistentClasses property. Neither helped this situation.
    The reason it seems is when the fromMapping() gets called. It only got
    called after calling execute() on my query. Thus, the rest of my mappings
    hadn't been loaded yet. I put a breakpoint in fromMapping(), and here was
    my stack trace:
    execute()
    executeWithArray()
    executeWithMap()
    internalCompile()
    getMetaDatas()
    getMappings()
    getMapping()
    getMappingInternal()
    getMapping()
    getMappingInternal()
    intialize()
    fromMapping()
    So, I need to figure out a way to get my code to read all the mappings
    before I do an execute(). I think. :) I'll investigate further unless
    you can give me a pointer in the right direction.
    Thanks!
    Steve
    PS: 1pm? 1PM? I'm here before 7am! But then, I usually leave at 4pm. :)
    Abe White wrote:
    Is the .mapping file preparsed, or is it only accessed when a class is
    requested from the datastore?
    We only resolve mappings when the classes are actually used. Have you
    listed all your persistent classes in the kodo.PersistentClasses
    configuration property, as suggested by the documentation for
    MetadataValueIndicator?
    PS: It's 5:37pm on a Friday. I'm going home. You should too! :)
    When you decide to start work at 1pm, you tend to stick around a little
    later.

  • Database access by Multiple users

    Hi All,
    I have a ztable and the user has to access the ztable to find the max of  ID to insert the next record. This ID increment was done in coding level. It was working fine when a user hit the DB. If multiple user access the same, it throws the error as duplicate records. How to solve this? Can any one give the soln for this?
    Thanks in Advance,
    Pon

    hi Murugesh,
    whenever you are updating the data into table through the report.
    you need to lock the table before inserting into the table and unloak after inserting the records into the Table.
    locking.
    FORM lock_spotter.
      LOOP AT gt_spotter INTO gs_spotter.
        CALL FUNCTION 'ENQUEUE_EZSPOTTERS'
             EXPORTING
                  mode_zspotters = 'E'
                  aktnr          = gs_spotter-aktnr
                  artnr          = gs_spotter-artnr
                  mebme          = gs_spotter-mebme
                  unique_key     = gs_spotter-unique_key
                  x_aktnr        = ' '
                  x_artnr        = ' '
                  x_mebme        = ' '
                  x_unique_key   = ' '
                  _scope         = '2'
                  _wait          = ' '
                  _collect       = 'X'
             EXCEPTIONS
                  foreign_lock   = 1
                  system_failure = 2
                  OTHERS         = 3.
        IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
        ENDIF.
      ENDLOOP.
      CALL FUNCTION 'FLUSH_ENQUEUE'
           EXCEPTIONS
                foreign_lock   = 1
                system_failure = 2
                OTHERS         = 3.
      IF sy-subrc <> 0.
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ENDIF.
    ENDFORM.
    unlocking
    LOOP AT gt_spotter INTO gs_spotter.
        CALL FUNCTION 'DEQUEUE_EZSPOTTERS'
             EXPORTING
                  mode_zspotters = 'E'
                  aktnr          = gs_spotter-aktnr
                  artnr          = gs_spotter-artnr
                  mebme          = gs_spotter-mebme
                  unique_key     = gs_spotter-unique_key
                  x_aktnr        = ' '
                  x_artnr        = ' '
                  x_mebme        = ' '
                  x_unique_key   = ' '
                  _scope         = '2'
                  _wait          = ' '
                  _collect       = ' '
             EXCEPTIONS
                  foreign_lock   = 1
                  system_failure = 2
                  OTHERS         = 3.
        IF sy-subrc <> 0.
          MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                  WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
        ENDIF.
      ENDLOOP
    hope this will help you.
    Regards,
    Madhavi

  • TDE Wallets & Multiple Databases on same Host

    The Oracle TDE Best Practices (doc ID 130696) states this:
    Multiple databases on the same host
    If there are multiple Oracle Databases installed on the same server, they
    must access their own individual TDE wallet. Sharing the same wallet between independent instances is not supported
    and can potentially lead to the loss of encrypted data.
    If the databases share the same ORACLE_HOME, they also share the same
    sqlnet.ora file in $TNS_ADMIN . In order to access their individual wallet, the
    DIRECTORY entry for the ENCRYPTION_WALLET_LOCATION
    needs to point each database to its own wallet location:
    DIRECTORY= /etc/ORACLE/WALLETS/$ORACLE_UNQNAME
    The names of the subdirectories under /etc/ORACLE/WALLETS/ reflect
    the ORACLE_UNQNAME names of the individual databases.
    If the databases do not share the same ORACLE_HOME, they will also have their individual sqlnet.ora
    files that have to point to the individual subdirectories.
    What is the correct sqlnet.ora syntax to do this?  I currently have what is below but it doesn't seem to be correct:
    ENCRYPTION_WALLET_LOCATION =
      (SOURCE = (METHOD = FILE)
      (METHOD_DATA =
      (DIRECTORY = /local/oracle/admin/wallet/DB#1)
      (DIRECTORY = /local/oracle/admin/wallet/DB#2)

    Hi,
    You can check this :Setting ENCRYPTION_WALLET_LOCATION For Wallets Of Multiple Instances Sharing The Same Oracle Home (Doc ID 1504783.1)
    i haven't done this for multiple database, but as per Doc you can use the syntex like
    ENCRYPTION_WALLET_LOCATION =
      (SOURCE = (METHOD = FILE)
      (METHOD_DATA =
      (DIRECTORY = /local/oracle/admin/wallet/$ORACLE_UNQNAME)
    Whenever you set the Environmnet with
    export $ORACLE_UNQNAME=DB#1 
    it will choose the file from respective directory like  /local/oracle/admin/wallet/DB#1
    HTH

  • Multiple DataBase Connection in a Single Form

    hi all
    Is it Possible to have Multiple Database Connection With a Single Form
    Block a : Retriving data from a database Service a/Schema A.
    Block b : Retriving data from a Remote Database Service b / Schema B.
    If yes how to do this.
    regards
    jai
    email:[email protected]

    Sure you can access a database this way,
    but can you base a block on this database connect? No you can't.
    Frank

  • How to add multiple databases for a single frontend

    We have a project based on distributed databases and we have to workout on .Net framework.I want to know some information of connecting multiple databases for a single frontend and how can we access them.
    If so we have connected 2 databases for a single frontend in future if I want add one more database to it how it will be possible to do it without disturbing the current connectivity.
    Please help me in resolving this problem.
    Thanks......

    hi,
    what do you mean by connecting 2 databases? can you explain further?
    using entityframework you can connect to different databases
    public class CustomerContext : DbContext
    public ReportContext()
    : base("DefaultConnection")
    public DbSet<Customers> Customers { get; set; }
    and your connectionstring (config file)
    <connectionStrings>
    <add name="DefaultConnection" connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=D:\\Database\Project.mdf;Integrated Security=True" providerName="System.Data.SqlClient" />
    </connectionStrings>
    you can add more connection strings on it.
    https://msdn.microsoft.com/en-us/library/vstudio/cc716756(v=vs.100).aspx
    https://msdn.microsoft.com/en-us/library/ms254978(v=vs.110).aspx
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

  • Multiple database users, ORM, entity framework, best practices

    Hello everyone!
    You've already helped me several times, however I must ask for an advice once more.
    I was assigned to develop .NET application with Data Access Layer and I've decided to use Oracle Database Software to provide sample data.
    As I'm absolute novice considering creating DAL I'd be grateful if you can examine my plan in terms of security and reliability:
    My database:
    1) I've created database with sample tables and relations between them. All tables belongs to databaseAdmin.
    2) I've created HR and Manager database users and granted them some privileges on certain databaseAdmin's tables. My intention is to reduce access to unnecessary tables. If my application user want to make some changes to Customers table it should be enough to connect to database as HR.
    And now I'd like to map my database using Entity Framework in my application. And that's where I have a problem:
    -If I create Entity Model basing on databaseAdmin tables I get perfect model, however every Entity SQL query would be executed on behalf of databaseAdmin, which breaks my idea of hiding unnecessary tables.
    -If I create Entity Model for HR and Manager users, my models could overlap on tables that both users have access to and no connection between tables would be generated (as from their point of view those tables are just some tables that belong to databaseAdmin)
    Could you help me with this deadlock? Or maybe my assumptions about multiple database users are incorrect? Please, bear in mind I'm a novice.
    I was trying to find a solution in web, and there're tons of data discussing technical aspects of Entity Framework etc., but not so many documents about conceptual model of database.

    hi Michael,
    Thanks for you posting!
    Sorry for I am not totally understanding your issue. Maybe two points need your confirm:
    1. I confuse with the "Service controller"? IS your meaning MVC controller? Or ServiceController(http://www.codeproject.com/Articles/31688/Using-the-ServiceController-in-C-to-stop-and-start
    2.whether  The type of ID in the model is match to the database ? In other words, Is the type of IDin .edmx matched to the database?
    By the way, it seems that this issue is more related to EF. You could post this issue on EF discussion for better support.
    Thanks & Regards,
    Will
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Multiple database in the same ADF application

    In my application I have to access a legacy database, in addition to the main database. How do I handle multiple database connections. Do I need to manage the JDBC connection to the legacy database myself.
    Pranab

    Use an AM for each dataconnection and then share the AMs so then can see each others datamodels.
    Or you can use jdbc in your code to access the databases.
    If would be nice if the adf had a way to connect to any data source set up in the configuration and app server on the fly.

  • Multiple Database Connections

    Trying to develop a functionality wherein we can view data of a remote database (not the database instance where APEX is installed) using the Report.
    As APEX doesnot support multiple database instance access from a single workspace/applciation.. any workarounds .. I'v used dblinks previously.. but was on a lookout for a more roboust solution..Dont find db links a reliable opiton.

    Hi,
    how about delving into the wonderful world of Web Services and XML?
    APEX is quite powerful in that realm.
    Of course WS adds a little overhead to communication and is a bit slower than a database link, but there are lots of benefits on the other hand. In my opinion it's the perfect option if you plan on loosely coupling your applications (not only APEX - ask the Java folks :-)
    It always depends on what your expectations are concerning "Quality of Service". A typical APEX page wouldn't load like a million of rows and therefore Web Services might be the right way.

  • Outer joins across multiple databases

    I'm trying to join three tables: 2 from data warehouse and 1 from Siebel database in OBIEE. I create the physical and logical joins (no errors or warnings). The model looks like this: Account Address (table 1) -> Account (table 2) -> Siebel Customer Data (table 3)
    I create two queries in Answers:
    (1) Account.Number and Siebel.Address (the query works)
    (2) Account Address.Zip, Account.Number, and Siebel.Address (the query gets the following error):
    State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 42019] Join condition, D901.c3 <> 0, contains predicates that are currently not supported for outer joins across multiple databases. (HY000)
    Can someone help me understand why the join between the two databases works for the first query but when I add a second table it fails?
    thanks...

    Either you can link the Oracle DB into Access (by using File/Get External Data/Link Tables)
    or you have to simulate the join in Java by doing two separate queries and looping through the results.

  • Multiple databases in one Environment

    I am tryiing to figure out the best way to implement my JE environment. My use case requires that I be able to use UNIX tools like 'cp' to move JE databases from place of generation (development) to place of consumption (production). Moreover, each JE database stores very different data and has different refresh cycles (ex., one of them may be refreshed every week, another may be refreshed once a month, etc.)
    My dilemma is:
    1)- Should I use one env w/multiple databases, or,
    2)- A separate env for each database?
    With (1), I can't see a way of selectively updating one of the databases and copying over the changed JE log files to production servers (for read-only access at runtime). Every time I want to update one database, I'm thinking I'll have to pull down all JE log files, update the DB and push out all JE log files to production servers.
    (2) seems to go against the guidelines I've seen in this forum, viz., one env per process is more efficient.
    Thoughts/experiences/comments are welcome.
    Thanks

    Hi,
    What Charles suggested is the best approach if you need to avoid the performance issues with having multiple environments in a single process (you mention that you've read about them elsewhere on the forum). Please also be aware that we're working to solve those problems in an upcoming release. So if you prefer, you can implement your application using multiple environments now, and expect that the performance issues will be resolved later. This might make sense if your deployment will be small at first, and performance will not be a big issue right away.
    Mark

Maybe you are looking for

  • I can't get itunes to work properly on my windows 8 computer

    Itunes will open and I can play music/videos etc, but it locks up while syncing my ipad andiphone and will not access the itunes store.  I've tried uninstalling and reinstalling itunes but it didn't make any difference.  HELP!!

  • How to move all data to another drive?

    I've just upgraded to Tiger and simultaneously installed two internal Seagate 325GB drives in mirror RAID configuration. I plan to keep the original 80GB drive for OSX and applications only, and move all documents, photos and music to RAID. But I'm n

  • Crash from sleep in Yosemitie

    Since I have upgraded my MacMini to Yosemite, my Mac Mini crashes when it wakes from sleep. I have it set to sleep from 1 AM until 8 AM. When I get home from work, it is at the login screen, and when I log in, it says that the system crashed, did I w

  • Item's onorder qty is negative.

    hi experts, I saw some items in my SBO have negative OnOrder quantities. i checked inventory status report and it also shows negative OnOrder quantity, but when I double click the row number to get the detailed information, there are no any quantitie

  • Problem in importing MPEG4 video

    When I import mpeg4 video using Element 8 I only see the clip as red. I do hear the sound but no video. Any suggestion on how to fix this. Thanks.