snippets / jdbc

All snippets tagged jdbc (1)

  1. A sample config for MySQL Connector/J 5.1 for Tomcat 5.5

    Replace path and docBase and etc. with your applications settings. This file assumes that this file is named apps-myapp.xml and is located under Tomcats configuration directory. It is also assumed that the application which is going to use MyConnection JDBC connection is called myapp and is accessed as http://yourdomain.tld/myapp and is located under Tomcats webapps directory. Database name is assumed my_database. Replace these with your actual values

      1 <?xml version="1.0" encoding="ISO-8859-1"?>
    2 <webapps>
    3 <Context path="/myapp" docBase="webapps/myapp" debug="0" reloadable="true">
    4 <!-- Replace path and docBase and etc. with your applications settings.
    5 This file assumes that this file is named apps-myapp.xml and is
    6 located under Tomcats configuration directory. It is also assumed that
    7 the application which is going to use MyConnection JDBC connection is
    8 called myapp and is accessed as http://yourdomain.tld/myapp and is
    9 located under Tomcats webapps directory. Database name is assumed
    10 my_database. Replace these with your actual values. -->
    11
    12
    13 <!-- This is a sample XML config file for an Apache Tomcat 5.5 server to
    14 setup MySQL Connector/J 5.1 for JDBC connectivity. Information are
    15 derived from sources available in the Internet. -->
    16
    17
    18 <!-- Resource name and ResourceParams name, must be the same and
    19 The connection pool will be bound into JNDI with that name
    20 Eg: "java:/comp/env/jdbc/MyConnection". Replace MyConnection in both
    21 places with the name you want for the connection. -->
    22 <Resource name="jdbc/MyConnection" auth="Container" type="javax.sql.DataSource"/>
    23 <ResourceParams name="jdbc/MyConnection">
    24
    25
    26 <parameter>
    27 <name>factory</name>
    28 <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
    29 </parameter>
    30
    31
    32 <!-- Don't set this higher than max_connections on your MySQL server,
    33 usually this should be a 10 or a few 10's of connections, not
    34 hundreds or thousands -->
    35 <parameter>
    36 <name>maxActive</name>
    37 <value>10</value>
    38 </parameter>
    39
    40
    41 <!-- Just allow only as many idle connections as you require. Too much
    42 is bad. -->
    43 <parameter>
    44 <name>maxIdle</name>
    45 <value>5</value>
    46 </parameter>
    47
    48
    49 <!-- Don't use autoReconnect=true, it's going away eventually and it's a
    50 crutch for older connection pools that couldn't test connections.
    51 You need to decide whether your application is supposed to deal with
    52 SQLExceptions (hint, it should), and how much of a performance
    53 penalty you're willing to pay to ensure 'freshness' of the connection -->
    54 <parameter>
    55 <name>validationQuery</name>
    56 <value>SELECT 1</value>
    57 </parameter>
    58
    59
    60 <!-- The most conservative approach is to test connections before they're
    61 given to your application. For most applications this is okay, the
    62 query used above is very small and takes no real server resources to
    63 process, other than the time used to traverse the network. If you have
    64 a high-load application you'll need to rely on something else. -->
    65 <parameter>
    66 <name>testOnBorrow</name>
    67 <value>true</value>
    68 </parameter>
    69
    70
    71 <!-- Otherwise, or in addition to testOnBorrow, you can test while
    72 connections are sitting idle -->
    73 <parameter>
    74 <name>testWhileIdle</name>
    75 <value>true</value>
    76 </parameter>
    77
    78
    79 <!-- You have to set this value, otherwise even though you've asked
    80 connections to be tested while idle,the idle evicter thread
    81 will never run -->
    82 <parameter>
    83 <name>timeBetweenEvictionRunsMillis</name>
    84 <value>10000</value>
    85 </parameter>
    86
    87
    88 <!-- Don't set this too high. A few minutes or even fraction of a minute
    89 is sometimes okay here, it depends on your application and how much
    90 spikey load it will see -->
    91 <parameter>
    92 <name>minEvictableIdleTimeMillis</name>
    93 <value>60000</value>
    94 </parameter>
    95
    96
    97 <!-- Username and password used when connecting to MySQL. Replace myuser
    98 and mypassword with your username/password for the database user. -->
    99 <parameter>
    100 <name>username</name>
    101 <value>myuser</value>
    102 </parameter>
    103 <parameter>
    104 <name>password</name>
    105 <value>mypassword</value>
    106 </parameter>
    107
    108
    109 <!-- Class name for the Connector/J driver -->
    110 <parameter>
    111 <name>driverClassName</name>
    112 <value>com.mysql.jdbc.Driver</value>
    113 </parameter>
    114
    115
    116 <!-- The JDBC connection url for connecting to MySQL, notice that if
    117 you want to pass any other MySQL-specific parameters you should
    118 pass them here in the URL, setting them using the parameter
    119 tags above will have no effect, you will also need to use &amp;
    120 to separate parameter values as the ampersand is a reserved
    121 character in XML. Replace my_database with your database name. -->
    122 <parameter>
    123 <name>url</name>
    124 <value>jdbc:mysql://yourdomain.tld:3306/my_database</value>
    125 </parameter>
    126
    127
    128 </ResourceParams>
    129 </Context>
    130 </webapps>
    Posted by Gaveen to xml jdbc mysql ... saved by 1 person ... 1 comments ... 8 months, 3 weeks
showing 10, 25, 50 items per pages

Pages : 1

Flux RSS friendsnippetLatest snippets


More...