blob: 02d2af3bb0ea066193dfe585af3d97061a33c8e9 [file] [log] [blame]
<div class="wiki-content maincontent"><p>We support a range of SQL databases for message persistence such as</p><ul><li>Apache Derby</li><li>Axion</li><li>DB2</li><li>HSQL</li><li>Informix</li><li>MaxDB</li><li>MySQL</li><li>Oracle</li><li>Postgresql</li><li><a shape="rect" href="sqlserver.html">SQLServer</a></li><li><a shape="rect" href="sybase.html">Sybase</a></li></ul><p>as well as a number of generic JDBC providers.</p><h3 id="JDBCSupport-Auto-discoveryofyourJDBCprovider">Auto-discovery of your JDBC provider</h3><p>We try to auto-detect from the JDBC driver which JDBCAdapter to use via these <a shape="rect" class="external-link" href="https://git-wip-us.apache.org/repos/asf?p=activemq.git;a=tree;f=activemq-jdbc-store/src/main/resources/META-INF/services/org/apache/activemq/store/jdbc">config files</a> and the return string from the JDBC driver.</p><p>If you have a JDBC database which we don't support then please let us know what JDBC driver string you're getting and <a shape="rect" href="discussion-forums.html">drop us a note</a> or raise an issue in our <a shape="rect" class="external-link" href="http://issues.apache.org/activemq/browse/AMQ">support database</a> and we'll fix it pretty quickly.</p><p>If your database is not in the above list it is normally a matter of tweaking the StatementProvider to ensure that the JDBCMessageStore uses the right flavour of SQL. So normally most databases support one of these providers...</p><ul><li>org.activemq.store.jdbc.adapter.BlobJDBCAdapter</li><li>org.activemq.store.jdbc.adapter.BytesJDBCAdapter</li><li>org.activemq.store.jdbc.adapter.DefaultJDBCAdapter</li><li>org.activemq.store.jdbc.adapter.ImageJDBCAdapter</li></ul><p>You can explicitly specify the JDBC adaptor using its xbean identifier, inside the activemq.xml...</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">&lt;jdbcPersistenceAdapter adapter="postgresql-jdbc-adapter"/&gt;
</pre>
</div></div><h3 id="JDBCSupport-CustomizingtheSQLDDL">Customizing the SQL DDL</h3><p>You can confiugure the various SQL datatypes - such as column sizes and so forth - using the statements element</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;"> &lt;broker useJmx="false"&gt;
&lt;persistenceAdapter&gt;
&lt;journaledJDBC useJournal="false"&gt;
&lt;statements&gt;
&lt;statements stringIdDataType ="VARCHAR(128)"/&gt;
&lt;/statements&gt;
&lt;/journaledJDBC&gt;
&lt;/persistenceAdapter&gt;
&lt;/broker&gt;
</pre>
</div></div><p>For more info on what attributes can be set on the statements element, see the <a shape="rect" class="external-link" href="http://activemq.apache.org/maven/apidocs/org/apache/activemq/store/jdbc/Statements.html">Statements class</a>. All the settable bean properties can be used as attributes of the &lt;statements&gt; element.</p><h3 id="JDBCSupport-UsingMySQL">Using MySQL</h3><p>If you are using MySQL then you should set the <strong>relaxAutoCommit</strong> flag to be true. e.g.</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;"> &lt;bean id="mysql-ds" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"&gt;
&lt;property name="driverClassName" value="com.mysql.jdbc.Driver"/&gt;
&lt;property name="url" value="jdbc:mysql://localhost/activemq?relaxAutoCommit=true"/&gt;
&lt;property name="username" value="activemq"/&gt;
&lt;property name="password" value="activemq"/&gt;
&lt;property name="poolPreparedStatements" value="true"/&gt;
&lt;/bean&gt;
</pre>
</div></div><p>To see this in action see the <a shape="rect" class="external-link" href="http://svn.apache.org/repos/asf/activemq/trunk/assembly/src/release/conf/activemq.xml">default configuration file</a></p><h3 id="JDBCSupport-ForAMQ3.x">For AMQ 3.x</h3><p>In 3.x you can specify the adapter as follows</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">&lt;jdbcPersistence adapterClass="org.activemq.store.jdbc.adapter.ImageBasedJDBCAdaptor"&gt;
...
&lt;/jdbcPersistence&gt;
</pre>
</div></div></div>