Can I access datasource properties programmatically?

Ask a Question related to Coldfusion - Advanced Techniques, Design and Development.

  1. #1

    Default Can I access datasource properties programmatically?

    I had an idea recently to include a description of the database within my
    application's XML config file. The idea being that upon initialization of the
    app, I could check the datasource to make sure it's setup how it needs to be
    for the app to work.

    So, I'm wondering if, given a datasource name and a defined datasource (I know
    you can't create those programmatically) if I could check the properties of the
    datasource to determine things like the database's name, type, etc.

    mate of the state Guest

  2. Similar Questions and Discussions

    1. Programmatically changing Adobe Pdf Print Properties
      Greetings, I have search all over to find an answer to this problem. I am driving MS Powerpoint with VB6 and also with Perl using Win32::OLE ...
    2. Access Article Threads from the SDK programmatically?
      Which SDK APIs if any provide to access Article Threads programmatically? If none, which 3rd party tools sufficiently provide this capability? ...
    3. Programmatically Get to User Control Properties
      I created a User Control, called in an Asp.Net page. First, I've registered the control at the top of the page: <%@ Register TagPrefix="uc1"...
    4. Programmatically inspect custom Object properties? ASP? PHP? ASP.NET?
      I've written a bunch of custom classes in ASP/VBScript. I'm wondering if there is a way to programmatically view the object's public properties,...
    5. Properties for User Controls loaded Programmatically
      I have x number of user controls that have a strong type (e.g. className uc1). I am able to access their properties through a single aspx page...
  3. #2

    Default Re: Can I access datasource properties programmatically?

    You could use the java.sql.DatabaseMetaData interface to access that
    information. The following example gets the version of the database using
    Oracle:

    <cfscript>
    Class = createObject("java","java.lang.Class");
    DriverManager = CreateObject("java", "java.sql.DriverManager");
    Class.forName("oracle.jdbc.driver.OracleDriver");
    con = CreateObject("java", "java.sql.Connection");
    con = DriverManager.getConnection("jdbc:oracle:thin:@ser vername:1521:orcl",
    "scott", "tiger");
    DatabaseMetaData = con.getMetaData();
    majorversion = DatabaseMetaData.getDatabaseMajorVersion();
    minorversion = DatabaseMetaData.getDatabaseMinorVersion();
    writeoutput("Database Version is " & majorversion &"." & minorversion);
    </cfscript>

    See the java.sql api at
    [url]http://brak/SoftwareLib/Trinity/Java/JavaSoft/J2SDK/Docs/1.4/api/index.html[/url].

    Ted Zimmerman

    tzimmerman Guest

  4. #3

    Default Re: Can I access datasource properties programmatically?

    Sounds neat, but your link is broken. It seems to be lacking a domain name... or appropriate domain suffix...
    mate of the state Guest

  5. #4

    Default Re: Can I access datasource properties programmatically?

    Sorry about that. Try [url]http://java.sun.com/j2ee/1.4/docs/api/index.html[/url] instead.

    Ted Zimmerman
    tzimmerman Guest

  6. #5

    Default Re: Can I access datasource properties programmatically?

    Could you guide me towards how to set this code up for a MySQL database? I've been looking around the JAVA documentation most of the morning, but I'm not a JAVA programmer.
    mate of the state Guest

  7. #6

    Default Re: Can I access datasource properties programmatically?

    Basically you would just have to substitue the mySQL driver and url information
    for the ones I used for Oracle:

    Class.forName("com.mysql.jdbc.Driver ");
    con = DriverManager.getConnection("jdbc:mysql://[host]:[port]/[database] ",
    "[username]", "[password]");

    HTH

    Ted Zimmerman




    tzimmerman Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139