Difference between revisions of "Connecting to a Database"

From CCIL
Jump to: navigation, search
(Created page with " Connection to various databases goes trough ''DatabaseConnectionManager'' class. In order to use it, you should add the following dependency to your project: <pre> <dependen...")
 
m
Line 8: Line 8:
 
<version>${ccil.version}</version>
 
<version>${ccil.version}</version>
 
</dependency>
 
</dependency>
 +
</pre>
 +
 +
== Usage ==
 +
 +
<pre>
 +
Connection cnn = db.getConnection();
 +
PreparedStatement st = (PreparedStatement) cnn
 +
      .prepareStatement("SELECT * FROM collections WHERE context = ?");
 +
st.setString(1, name);
 +
ResultSet rs = st.executeQuery();
 
</pre>
 
</pre>

Revision as of 07:53, 13 June 2016

Connection to various databases goes trough DatabaseConnectionManager class. In order to use it, you should add the following dependency to your project:

<dependency>
	<groupId>net.ccil</groupId>
	<artifactId>ccil-common-sql</artifactId>
	<version>${ccil.version}</version>
</dependency>

Usage

Connection cnn = db.getConnection();
PreparedStatement st = (PreparedStatement) cnn
       .prepareStatement("SELECT * FROM collections WHERE context = ?");
st.setString(1, name);
ResultSet rs = st.executeQuery();