Rust-JDBC bindings

Overview

jdbc

A Rust library that allows you to use JDBC and JDBC drivers.

Usage

First, add the following to your Cargo.toml:

[dependencies]
jdbc = "0.1"

Next, add this to your crate root:

extern crate jdbc;

Then you can in your main function do something like this:

let jvm_options = ["-Djava.class.path=./jars/postgresql-42.1.1.jar", "-Xcheck:jni"];
let _ = unsafe { jvm::JVM::from_options(&jvm_options) };

let url = "jdbc:postgresql://localhost/test";

let connection = DriverManager::get_connection(url).unwrap();
let statement = connection.create_statement().unwrap();
let result_set = statement.execute_query("SELECT * FROM customers").unwrap();
let metadata = result_set.get_meta_data().unwrap();
let columns = metadata.get_column_count().unwrap();

while result_set.next().unwrap() {
  print!("row:");
  for i in 1 .. columns + 1 {
    print!(" {:?}", result_set.get_string(i).unwrap());
  }
  println!("");
}

What is jdbc?

The primary purpose of this crate is to allow you to use Java JDBC database drivers from Rust in a convenient way with a relatively safe interface. It does this via embedding a JVM in your process so be aware that if you use JNI in some other way in your app you will need to tell jdbc to play nice.

Platforms

I am testing on my Mac, but I would love to setup some CI to get this party started.

Contributing

Patches are welcome, don't forget to add yourself to the Authors list.

Authors

You might also like...
Safe Rust --- GraalVM Polyglot bindings using procedural macros

The class macro is the primary way to generate bindings to Java types; it will generate a struct (with generics if specified) that implements Pass and Receive and has all the methods you give stubs for. The methods generated can be used like normal rust methods, however mutability is not enforced. The fully-qualified type name should precede a block containing method and constructor stubs. Java primitives like char, int, and byte are aliased to corresponding Rust types.

Rust bindings for accessing the Go containers/image stack

Rust bindings for accessing the Go containers/image stack This crate contains a Rust API that forks /usr/bin/skopeo and talks to it via a custom API.

Rust bindings for accessing the Go containers/image stack

Rust bindings for accessing the Go containers/image stack This crate contains a Rust API that forks /usr/bin/skopeo and talks to it via a custom API.

Implementation of Monte Carlo PI approximation algorithm in Rust Python bindings

rusty_pi Implementation of Monte Carlo PI approximation algorithm in Rust Python bindings. Time of 100M iterations approximation on Core i7 10th gen:

luau - Rust bindings to Roblox's Luau

luau - Rust bindings to Roblox's Luau This library is an interface between Rust and Luau. It aims to be easy-to-use, fast, and safe (kind of like rlua

luau bindings for the Rust programming language

🌔 luau-rs Luau bindings for the Rust programming language using bindgen ⚠️ Disclaimer This does not provide bindings for everything as luau does not

React bindings for rust

react-sys Rust bindings for React. WIP This crate is NOT ready for production and is under heavy development. This crate intends to be used by frender

Rust Blake hash bindings for Node.js.

@napi-rs/blake-hash Node.js binding for https://github.com/BLAKE3-team/BLAKE3. High performance, and no postinstall scripts. Support matrix node12 nod

(WIP) Rust bindings to QuickJS

(WIP) rusty_qjs Rust bindings to QuickJS. Todo JSValue::new_... returns a Result specific JSValue type, like JsString, JsNumber...? catch unwind for e

Comments
  • Overlap with Rucaja

    Overlap with Rucaja

    Hi,

    i've noticed that you've written similar code in order to instantiate and use the JVM as i've had in Rucaja for Tinkerpop-rs.

    Maybe there is code/best practises to be shared. It would be especially interesting to come up with a type-safe but ergonomic API.

    opened by kud1ing 7
  • rust-jdbc/jvm are not currently on crates.io and example doesn't link jvm

    rust-jdbc/jvm are not currently on crates.io and example doesn't link jvm

    Both rust-jdbc and rust-jvm are not on the crates.io repo. I currently can build both using rust nightly "cargo +nightly build". BUT when I try to build the provided example source, I get cc linker error -ljvm not found. I tried to point it to the java sdk's libjvm.so but it still fails to link and I have not successfully run any examples with your rust-jdbc yet.

    Thank you for listening.

    opened by omac777 0
  • What is performance like?

    What is performance like?

    I made a java Jetty server daemon to expose SELECT/UPDATE/DELETE/INSERT operations of a JDBC driver.

    I'd be curious how performance with HTTP + JSON serialization/deserialization overhead would compare to this.

    opened by brandonros 0
Owner
Aurora
Aurora
A project for generating C bindings from Rust code

cbindgen   Read the full user docs here! cbindgen creates C/C++11 headers for Rust libraries which expose a public C API. While you could do this by h

Ryan Hunt 1.7k Jan 3, 2023
Automatically generates Rust FFI bindings to C (and some C++) libraries.

bindgen bindgen automatically generates Rust FFI bindings to C (and some C++) libraries. For example, given the C header doggo.h: typedef struct Doggo

The Rust Programming Language 3.2k Jan 4, 2023
Lua 5.3 bindings for Rust

rust-lua53 Aims to be complete Rust bindings for Lua 5.3 and beyond. Currently, master is tracking Lua 5.3.3. Requires a Unix-like environment. On Win

J.C. Moyer 150 Dec 14, 2022
Safe Rust bindings to Lua 5.1

rust-lua Copyright 2014 Lily Ballard Description This is a set of Rust bindings to Lua 5.1. The goal is to provide a (relatively) safe interface to Lu

Lily Ballard 124 Jan 5, 2023
mruby safe bindings for Rust

mrusty. mruby safe bindings for Rust mrusty lets you: run Ruby 1.9 files with a very restricted API (without having to install Ruby) reflect Rust stru

Anima 200 Oct 12, 2022
Rust bindings for writing safe and fast native Node.js modules.

Rust bindings for writing safe and fast native Node.js modules. Getting started Once you have the platform dependencies installed, getting started is

The Neon Project 7k Jan 4, 2023
Objective-C Runtime bindings and wrapper for Rust.

Objective-C Runtime bindings and wrapper for Rust. Documentation: http://ssheldon.github.io/rust-objc/objc/ Crate: https://crates.io/crates/objc Messa

Steven Sheldon 336 Jan 2, 2023
High-level Rust bindings to Perl XS API

Perl XS for Rust High-level Rust bindings to Perl XS API. Example xs! { package Array::Sum; sub sum_array(ctx, array: AV) { array.iter().map(|

Vickenty Fesunov 59 Oct 6, 2022
Rust <-> Python bindings

rust-cpython Rust bindings for the python interpreter. Documentation Cargo package: cpython Copyright (c) 2015-2020 Daniel Grunwald. Rust-cpython is l

Daniel Grunwald 1.7k Dec 29, 2022
Rust bindings for the Python interpreter

PyO3 Rust bindings for Python. This includes running and interacting with Python code from a Rust binary, as well as writing native Python modules. Us

PyO3 7.2k Jan 4, 2023