The MindsDB Java SDK allows you to connect to a MindsDB server from Java using the HTTP API.
To use the MindsDB Java SDK, include the following dependency in your pom.xml
:
<dependency>
<groupId>com.mindsdb</groupId>
<artifactId>mindsdb-java-sdk</artifactId>
<version>1.1.0</version>
</dependency>
You can establish a connection to the MindsDB server using the SDK. Here are some examples:
import mindsdb.MindsDB;
import mindsdb.services.Server;
public class Main {
public static void main(String[] args) {
// Running locally on http://127.0.0.1:47334 or http://localhost:47334
Server server = MindsDB.connect();
Server serverWithUrl = MindsDB.connect("http://127.0.0.1:47334");
}
}
Once connected to the server, you can perform various operations. Here are some examples:
import mindsdb.models.Database;
import java.util.List;
public class Main {
public static void main(String[] args) {
Server server = MindsDB.connect();
List<Database> databases = server.listDatabases();
}
}
import mindsdb.models.Database;
public class Main {
public static void main(String[] args) {
Server server = MindsDB.connect();
Database database = server.getDatabase("my_database");
}
}
import mindsdb.models.Database;
import mindsdb.models.Query;
public class Main {
public static void main(String[] args) {
Server server = MindsDB.connect();
Database database = server.getDatabase("my_database");
Query query = database.query("SELECT * FROM table1");
System.out.println(query.fetch());
}
}
import mindsdb.models.Database;
import mindsdb.models.MDBTable;
import tech.tablesaw.api.Table;
public class Main {
public static void main(String[] args) {
Server server = MindsDB.connect();
Database database = server.getDatabase("my_database");
Table tableData = Table.read().csv("path/to/csv");
MDBTable table = database.createTable("table2", tableData, true);
}
}
import mindsdb.models.Project;
public class Main {
public static void main(String[] args) {
Server server = MindsDB.connect();
Project project = server.getProject("my_project");
}
}
import mindsdb.models.Project;
import mindsdb.models.Query;
public class Main {
public static void main(String[] args) {
Server server = MindsDB.connect();
Project project = server.getProject("my_project");
Query query = project.query("SELECT * FROM database.table JOIN model1");
}
}
import mindsdb.models.Project;
import mindsdb.models.View;
import mindsdb.models.Query;
public class Main {
public static void main(String[] args) {
Server server = MindsDB.connect();
Project project = server.getProject("my_project");
Query query = project.query("SELECT * FROM database.table JOIN model1");
View view = project.createView("view1", query);
}
}
import mindsdb.models.Project;
import mindsdb.models.View;
import java.util.List;
public class Main {
public static void main(String[] args) {
Server server = MindsDB.connect();
Project project = server.getProject("my_project");
List<View> views = project.listViews();
View view = views.get(0);
System.out.println(view.fetch());
}
}
import mindsdb.models.Project;
import mindsdb.models.Model;
import java.util.List;
public class Main {
public static void main(String[] args) {
Server server = MindsDB.connect();
Project project = server.getProject("my_project");
List<Model> models = project.listModels();
Model model = models.get(0);
}
}
import mindsdb.models.Project;
import mindsdb.models.Model;
import tech.tablesaw.api.Table;
public class Main {
public static void main(String[] args) {
Server server = MindsDB.connect();
Project project = server.getProject("my_project");
Model model = project.getModel("model1");
Table inputData = Table.read().csv("path/to/csv");
Table result = model.predict(inputData);
System.out.println(result);
}
}
import mindsdb.models.Project;
import mindsdb.models.Model;
import mindsdb.models.Query;
import java.util.HashMap;
import java.util.Map;
public class Main {
public static void main(String[] args) {
Server server = MindsDB.connect();
Project project = server.getProject("my_project");
Query query = project.query("SELECT * FROM database.table");
Map<String, Object> timeseriesOptions = new HashMap<>();
timeseriesOptions.put("order", "date");
timeseriesOptions.put("window", 5);
timeseriesOptions.put("horizon", 1);
Model model = project.createModel("rentals_model", "price", query, timeseriesOptions);
}
}
import mindsdb.models.Project;
import mindsdb.models.Model;
public class Main {
public static void main(String[] args) {
Server server = MindsDB.connect();
Project project = server.getProject("my_project");
Model model = project.getModel("rentals_model");
System.out.println(model.describe());
}
}
The API documentation for the MindsDB SDK can be found at md-abid-hussain.github.io/mindsdb-java-sdk/.
cd docs
mvn clean install
mvn site
The online documentation is automatically updated by pushing changes to the docs
branch.
To run all the tests for the components, use the following command:
mvn test
We welcome contributions to the MindsDB Java SDK. If you'd like to contribute, please refer to the contribution guidelines for more information.
The MindsDB Java SDK is licensed under the GNU License. Feel free to use and modify it according to your needs.