Get Database Schema Name

Hi,
I am trying to retrieve the schema name from my application so I can perform some ALTER DATABASE `foo`... statements in MySql which ensure database intergrity for my application. Ideally i would want to accomplish this without having to run a regular expression on my connect url:
url="jdbc:mysql://localhost:3306/bad2?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true"
which already has the default schema/database I am using. I was wondering if there is some JDBC standard method that all drivers comply to as I would rather avoid having to write some conditional, vendor specific code. Ideally this will be present in DatabaseMetadata.Thanks,
Nedko
http://www.nedkoko.com
Edited by: nedKoKo.com on Oct 11, 2007 10:55 AM
Edited by: nedKoKo.com on Oct 11, 2007 11:25 AM

Owen unfortunately Connection.getCatalog() works well with all databases but Oracle which gets me back to square 1 of the problem. My application is designed to use different database vendors among which are MySql, MsSQL and Oracle. A standard connection URL should work fine and connect to the specified schema of your choice. The problem however is that the Connect URL string in Oracle is different and does not specify the default schema:
Mysql: url="jdbc:mysql://localhost:3306/database_name?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true"
MsSQL: url="jdbc:jtds:sqlserver://sqlserver:1433/database_name;SelectMethod=cursor"
Oracle: url="jdbc:oracle:thin:@bart:1521:orcl"
The oracle URL is constructed according the specs (http://www.oracle.com/technology/tech/java/sqlj_jdbc/htdocs/jdbc_faq.htm#05_03) and does not specify schema by default but just SID name. As I am using Hibernate persistence in my J2EE app I am forced to specify "schemaName" when I initialize my environment which works fine but is Oracle specific. On the other hand Connection.getCatalog() works great with other vendors but returns NULL for Oracle. Ideally i want to be able to resolve everything in a unified way and not have to write vendor specific code. Any suggestions are appreciated.
Nedko

Similar Messages

  • How to Get the schema name that contains the current procedure?

    I have try select sys_context( 'userenv', 'current_schema' ) from dual; but it returns the schema name of the login user. How to return the schema name of the procedure instead? For example, procedure A is in ControlDB, and I login as sys, when query procedure A it should return ControlDB instead of sys.
    I have searched in Google but no luck to find the answer so far, please help. Thank you

    It works!
    I am quite confused now. I did try to use select username from user_users in GetSchemaName procedure, but it always return the login user instead of the owner of the procedure. Why it return the procedure owner if I put the query inside a function then call it from the procedure?
    Is it because when the login user call the procedure and the procedure call the function, it's the procedure owner is calling the function so the user_users return the user that is calling it which is the procedure owner. And if the query is directly put inside the procedure, when the login user call the procedure, user_users return the login user directly? Does it imply that if the procedure call any function or other procedures etc, it would be the procedure's owner calling them instead of the login user?
    (sys_context works as well if I move the query into the function then call the function from the procedure)
    Cheers
    Message was edited by:
    user500168

  • How to get Database Vendor Name or Database Type...

    Hello,
    Is it possible to get the vendor or database from jdbc connection?
    Or maybe from the loaded Driver Class...
    The classpath and the jdbcurl seems not to be the right way
    Greetings & Thanks
    Peter

    void printDBInfo(Connection con) {
       try {
          DatabaseMetaData conMD = con.getMetaData();
          System.out.println("Driver Name: " + conMD.getDriverName());
          System.out.println("Driver Version: " + conMD.getDriverVersion());
          System.out.println("Database Name: " + conMD.getDatabaseProductName());
          System.out.println("Database Version: " + conMD.getDatabaseMajorVersion());
       } catch (Exception ex) {
          ex.printStackTrace();
    }

  • How can let oc4j use my database schema file?

    I wrote a mysql.xml in config\database-schemas.
    But when I deploy a ejb application, It reported:
    2005-2-20 4:11:03 com.evermind.server.Application getDatabaseSchema
    Warning: Exception occurred getting database schema. Exception: java.sql.
    SQLException: Can't call commit when autocommit=true
    2005-2-20 4:11:04 com.evermind.server.Application getDatabaseSchema
    Warning: Warning: Exception occurred getting database schema. Exception: java.sql.
    SQLException: Can't call commit when autocommit=true
    05/02/20 04:11:05 Auto-deploying - compiling and loading...
    Note: Some input files use or override a deprecated API.
    Note: Recompile with -deprecation for details.
    05/02/20 04:11:22
    Auto-creating table: create table Student_ejb1_ejb1 (id BIGINT not null primary
    key, name SET(255) null)
    05/02/20 04:11:22 Error creating table: You have an error in your SQL syntax; ch
    eck the manual that corresponds to your MySQL server version for the right syntax....
    Do I need write schema property in data-sources.xml?

    To the data-sources.xml configuration file add a datasource element for MySQL. In the schema attribute set the schema file to database-schemas/mysql.xml.
    <data-source
        class="com.mysql.jdbc.jdbc2.optional.MysqlDatasource"
        name="OracleDS”
        schema="database-schemas/mysql.xml"
        location="jdbc/mySQLCoreDS"
        xa-location="jdbc/xa/mySQLXADS"
        ejb-location="jdbc/mySQLDS"
        connection-driver="com.mysql.jdbc.Driver"
        username=""
        password="”
        url="jdbc:mysql://localhost/test"
        />   

  • Schema name dependancy for DB Adapters in OSB

    Hello,
    We are having a problem with the DBAdapters used in OSB.
    We have created a DBAdapter in our developement env where the database schema name dev_utilities.In our test env the schema name is test_utilities.
    The DBAdapter in OSB would not work giving errors dev_utilities is invalid.
    Anyway to fix this.We have same connection pool names though.
    Thanks.

    Are you using a managed connection.
    when you use a managed connection it will not check for connection details in your wsdl instead it will get from the server using the jndi name that you have specified.
    you can go through below link for creating managed connection
    http://tech-learnings.blogspot.com/2010/04/creating-data-source-in-soa-11g.html
    http://kr.forums.oracle.com/forums/thread.jspa?threadID=1083177

  • How do I select a database schema to use for a sequence file?

    I have multiple database schemas on my TestStand system and when I select a sequence file I need to set the schema so the results get entered into the database correctly.
    I use a SequenceFileCallback for DatabaseOptions in my sequence file and in this I set Parameters.DatabaseOptions.DatabaseSchema.Name='xyz' where xyz is the database schema name that needs to be used. This does not work and it reports an error that it can not be loaded or the file may be corrupted. Does this feature work or do I just have an error in what I am setting this equal to?
    Solved!
    Go to Solution.

    Hi plf,
    It seems to me you are going about this the right way. The DatabaseOptions callback is called immediately before the process model fetches the schema statements based on the schema name. I was able to change the schema on the fly in the same way you are attempting (using the default sequential model and TestStand  4.1).
    Ensure you are using a schema that is defined in the Database Options Dialog (Configure»Database Options»Schemas Tab»Schemas Listbox).
    Ensure you are using the exact name of the desired schema (copy it from the Name textbox in the above Schemas Tab).
    Ensure that choosing this schema manually works when you run this sequence file (to be sure it is not corrupted).
    Check that you are using double quotation marks around the schema name, not single marks as in your post.
    Evan Prothro
    RF Systems Engineer | NI

  • JCA database adapter issue due to database schema dependency

    Hi,
    I am using the JCA database adapter to call a stored procedure. The adapter uses the database schema name while calling the Stored procedure. The schema name is added in the namespace of XSD, wsdl files.
    If I have to use a different database schema name, how can I update the existing code without much modification.
    Thanks!

    Thanks for your reply Prabhu.
    But the modification in JCA file is resulting in the following Exception.
    I think this change has resulted in references related issue. Please let me know if any further changes are required.
    <> <Error> <oracle.soa.adapter> <BEA-000000> <JCABinding=> Could not invoke operation against the 'Database Adapter' due to:
    BINDING.JCA-11811
    Stored procedure invocation error.
    Error while trying to prepare and execute the old_schema_name.stored_procedure_name.
    An error occurred while preparing and executing the old_schema_name.stored_procedure_name.
    API. Cause: java.sql.SQLException: ORA-06550: line 1, column 7:
    PLS-00201: identifier old_schema_name.stored_procedure_name.
    must be declared
    ORA-06550: PL/SQL: Statement ignored

  • Rename database Schema

    Is they any method to rename database schema name apart from taking export and import uitlities.
    Eg:- Alter user rename xx to yy;

    No and it bugs the hell out of me! Like you say
    you'll either have to use the fromuser - touser
    syntax in import or the remap_schema option in
    datapump. Another annoyance are the inflexibility of
    oracle privileges. I want a simple command to say
    grant insert on all tables in a particular schema
    without having to list them out using object
    privileges or using the ANY syntax meaning that a
    user can insert into any schemas table.But this is what roles are for. You create the role and grant the role to the user.
    With a bit of pl/sql it would be quite straightforward to create a role which had all the tables in a schema.

  • Plsql directives schema name

    Hi,
    Is it possible to get the schema name of a package easily, just like you could use $$PLSQL_UNIT for the package name?
    Thanks,
    Jan

    Assuming you have a definer rights package (not invoker rights) and you want to get the package owner (not the user who called the package), then you can simply:
    select username from user_users;You can use package variable and package initialization section:
    CREATE OR REPLACE PACKAGE BODY mypkg AS
      g_schemaowner     user_users.username%TYPE;
    -- your functions and procedures here
    BEGIN
      SELECT username INTO g_schemaowner FROM user_users;
    END;
    /

  • DATABASE SERVICE NAME

    HOW TO GET DATABASE SERVICE NAME?
    I NEED IT INORDER TO INSTALL COMPANION PRODUCTS?
    ANY HELP
    THANKS ANYWAY

    This is what i recieve when i click on help regarding database service name?
    "Database Service Name Specify the database service name for the database where you want to install the Oracle HTML DB database objects. The database service name is usually the same as the global database name for the database, for example, sales.us.oracle.com."
    but I don't have domain name. I installed Oracle on a standalone machine for testing purposes.Do I need to be on a network using HTML DB??
    MY DB NAME IS GPI, CONNECTION STRING IS
    (DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=GPI)))
    BUT IT IS NOT WORKING?
    AND WHAT IS WINDOWS DATABASE SERVICE NAME?

  • How get all table name from database

    hi master
    sir
    how get all table name from database

    The big question is 'why'.
    Selecting from view 'dba_tables' will indeed give the list of all tables in the database, but that includes the dictionary tables and the internal tables, and many others that are probably not of interet to a person who needs to ask this question. Besides, the dba_tables view requires access to a DBA account.
    There are several other views: "user_tables" will list all the tables in this user's schema; and "all_tables" will list all the tables this user can access in some way.
    The above do not, of course, include any information about synonyms, sequences, views, indexes and so on.
    The correct answer and the meaningful answer may be two different things.

  • New User Database schema and table name

    When i create a new user in Oracle Webcenter Spaces 11g, I am not able to get the name of the database schema and table, where it is stored. Any insight on this will be very helpful.

    WebCenter (and WebCenter spaces) uses an 'identity store' instead of database schema for storing user information - in an 'out of the box' installation, users are maintained through an embedded WebLogic LDAP store.
    See the Oracle Fusion Middleware Administrator's Guide for Oracle WebCenter, p. 34-2.
    At the end of section 34.4.1:
    WebCenter Spaces supports self-registration. When new WebCenter users
    self-register, they create their own login and password and a new user account is
    created in the identity store. See also, Section 34.4, "Allowing Self-Registration".
    user9097357 wrote:
    When i create a new user in Oracle Webcenter Spaces 11g, I am not able to get the name of the database schema and table, where it is stored. Any insight on this will be very helpful.

  • How to know database name and schema name

    Hi ,
    Once after logging in the database,how is it possible to know the current database and schema which we r using?Is there any system table where we can get the database names and schema names?
    please help me out.itz urgent.
    Regards,
    Sravan

    Probably not.
    If the database name is the name of the current database, it would be essentially redundant. If the database name is the name of some other database, in order to get the names of all the tables in the specified schema, you could create a database link to the remote system (which assumes you have a login and password to the remote database with appropriate privileges, that the database server's tnsnames.ora file has an entry for the remote database, etc) and query the remote data dictionary tables. Even if you could do that, however, you could not dynamically create triggers on the remote database since DDL over a database link.
    In theory, you could also load an appropriate JDBC driver into the database and write a Java stored procedure that would connect to the remote database (again, with an appropriate user name & password, host name, and port number) and issue DDL against that remote database. I have a hard time believing, however, that this would be a particularly beneficial approach. It would be easier just to put the appropriate code into each database that needs triggers generated or to have a separate Java application that generates triggers for a number of different databases.
    Justin

  • How to know database name and schema name by providing package name?

    Hi,
    Could someonw will help me to get database name and schema name by providing package name ?
    I have used the query : select * from all_objects where object_name='Package_name'; but it simply returns schema name where as i need DB name and username.
    --Prajakta

    but it simply returns schema name where as i need DB name and username.
    i want to retrive the DB name for package name
    Based on your questions, I wonder if you are used to working in SQL Server? (The server, database, and schema are part of the 4-part  name of an object, independent of any user.)
    In SQL Server, schema and username are two separate physical concepts.  "Schema" is purely logical in Oracle: a user which owns objects is often called a "schema".
    In Oracle, "database" is roughly equivalent to the SQL Server concept  "server" (what you log in to).  It is not part of the naming path to a specific object  (unless there is a database link involved, but there is no indication that's what you have here).  In Oracle you connect to an Instance (or Service) and people often call this the "database", but there is a fine semantic distinction there (separate topic). 
    Once connected in Oracle, you fully-qualify an object by only a 2-part owner and object name (possibly 3-part if a database link is involved user.object@link).
    12c added another wrinkle to all of this, but I'll assume this question was more basic than that, because you likely would have mentioned if this was a 12c question.

  • Get the table names from a specified schema name

    Can't any one can hlep me how to use OCIDescribeAny() to retrive the list of table names for a given schema name?
    I have problem when I connect to the database using syste as usr id. I can't ge the table name form the SCOTT schema.

    If I understand you correctly, I don't think OCIDescribeAny() is the way to go.
    You can get a list of tables owned by a particular schema by using the following SQL:-
    SELECT TABLE_NAME FROM DBA_TABLES WHERE OWNER = 'SCOTT'
    Just change the where clause to your needs.
    Regards.
    Adrian

Maybe you are looking for

  • Query in Select query operation

    Please excuse me for posting this again. I'm stuck up with this for 3 days. Lenghty post pls do read and help me. How is the select query going to be changed in the SAP so that the original database behind it understands it. I want to know the operat

  • ASA9.1 how to use route-lookup instead of "NAT-lookup" for egress interface on non-identity NAT

    Hi, I have an ASA firewall with three interfaces, inside, outside and Link. I have a situation where I need the ASA to perform the following nat rules: from "Inside" to "Link" - any source to destination 192.168.51.0/24 - translate source to 10.0.0.1

  • Tax calculation in shipment document

    Hi Experts, We have shipment document and cost calculation in place for inbound material. Now we have one requirement that at the time of GR the following entry should be posted; Inventory Dr GR/IR       Cr Freight Clg Cr Service tax on Freight Cr-pa

  • Recording Live TV in DV Quality

    Is there a way to watch and record live televsion in .dv quality video on my Mac? I was looking for a hardware, software combo? I looked at the El Gato stuff, but it doesn't seem to be of the highest quality video. 1 to 2 GB's would record one hour o

  • -2 unknown error when trying to access acount

    I cannot access my account information. After entering my password I get the following error: "We could not complete your iTunes Store request. An unknown error occurred (-2)." This has been going on all day. I can browse the store and play audio sam