Data
JDBC
Overview
Data can be sent from/to 3forge using a JDBC connection. This connection is controlled by the configuration file (see the Configuration Guide for more details).
| The port for connecting to 3forge via the JDBC driver. Default is 3280
ami.db.jdbc.port=3280
Optional. Specifies the network interface that the ami.db.jdbc.port server port will be bound to
ami.db.jdbc.port.bindaddr=
# provide either a list of permitted hostname patterns or plugin for blocking/granting access based on foreign network address. Syntax is either file:<file_containing_a_hostname_patterns_per_line> or text:<comma_delimited_list_of_hostname_patterns> or plugin:<class_name_implementing_com.f1.ami.amicommon.AmiServerSocketEntitlementsPlugin>
ami.db.jdbc.port.whitelist=
# By default pointing to ${ami.db.auth.plugin.class}, which sets target database's JDBC endpoints
ami.jdbc.auth.plugin.class:=${ami.db.auth.plugin.class}
|
Example: Java
| import java.sql.*;
public class AmiJdbcSample {
//IMPORTANT NOTE: be sure to include out.jar in your java classpath. The out.jar file is located in the lib folder of your ami installation
public static final String NEW_LINE = System.getProperty("line.separator");
public static void main(String a[]) throws SQLException, ClassNotFoundException {
Class.forName("com.f1.ami.amidb.jdbc.AmiDbJdbcDriver");
final String url = "jdbc:amisql:localhost:3280?username=demo&password=demo123";
final Connection conn = DriverManager.getConnection(url);
try {
final ResultSet rs = conn.createStatement().executeQuery("select * from __TABLE");
System.out.println(resultSetToString(rs));
} finally {
conn.close();
}
}
public static String resultSetToString(ResultSet rs) throws SQLException {
final StringBuilder r = new StringBuilder();
final ResultSetMetaData metaData = rs.getMetaData();
final int columnCount = metaData.getColumnCount();
for (int i = 1; i <= columnCount; i++)
r.append(metaData.getColumnName(i)).append(i == columnCount ? NEW_LINE : "\t");
while (rs.next())
for (int i = 1; i <= columnCount; i++)
r.append(rs.getObject(i)).append(i == columnCount ? NEW_LINE : "\t");
return r.toString();
}
}
|
Example: Python
Prerequisites: A jre (Java runtime environment, for JDBC) needs to be installed.
-
Install the JayDeBeApi module.
JayDeBeApi is an adapter of JDBC for python. You can install it using pip:
Alternative ways to install JayDeBeApi: https://pypi.org/project/JayDeBeApi/
-
Start AMI One.
-
Connect to amisql from python:
-
You'll need the path to the out.jar file. This can be found in the ami/amione/lib folder.
-
Find the server hostname and ami.db.jdbc.port (default is 3280).
-
Copy this script, replacing the <placeholders> with appropriate values:
| import jaydebeapi
conn = jaydebeapi.connect("com.f1.ami.amidb.jdbc.AmiDbJdbcDriver",
"jdbc:amisql:<hostname>:<port>",
{"user": "<username>", "password": "<password>"},
"<path/to/out.jar>")
|
-
To run queries, create a cursor:
-
Queries can then be executed using the execute method:
| curs.execute("show tables")
|
-
Results are fetched using the fetchall method, which returns a list:
-
Close the cursor once finished:
You can also execute queries within a with block for the cursor so you don't have to worry about closing it:
| with conn.cursor() as curs:
curs.execute("show tables")
result = curs.fetchall()
|
Example: DBeaver
-
Add driver configuration in DBeaver:
- Go to Database -> Driver Manager, Open driver manager dialogue and click New.

- Configure the AMIDbJdbcDriver.

| Parameter |
Description |
Example |
| Driver Name |
Name of your driver. It can be any name you like |
AmiDbJdbcDriver |
| Driver Type |
Driver Provider |
Generic |
| Class Name |
JDBC driver class name |
com.f1.ami.amidb.jdbc.AmiDbJdbcDriver |
| URL Template |
Template of driver URL, should follow the format like: jdbc:amisql:<host>:<jdbc port><login details> |
jdbc:amisql:localhost:3280?username=demo&password=demo123 |
| Default Port |
Default AMI JDBC port is 3280 |
3280 |
| Default Database |
Default database is AMI |
AMI |
| Default User |
Default user name is demo |
demo |
| Description |
Description of the driver |
driver for connection to AMIDB |
- Go to Libraries tab and add the out.jar file(/amione/lib/out.jar) into it and hit ok.

-
Establish Database Connection With the AMIDbJdbc Driver:
- Go to Database -> New Database Connection and select the AMIDbJdbc driver we just configured.

- Enter the URL and your login information. Your 3forge Database is ready to go.
