Code Monkey home page Code Monkey logo

jdbc-rs's Introduction

jdbc-rs

中文 | English

Rust bindings to the Java Jdbc.

Many databases today do not have official support for Rust, so many databases cannot be connected using Rust. However, most databases officially provide Java version of JDBC drivers, and these drivers are very stable.

Using this library, you can use Java's JDBC to connect to any type of database.

Rust does not have an official database-driven abstraction, and the most widely used unofficial crate is Sqlx. The ultimate purpose of this library is to provide the implementation of sqlx to temporarily support databases not supported by Sqlx.

English documentation uses Google Translate.

Getting Started

Introduce Rust dependencies

Cargo.toml

[dependencies]
jdbc = "0.1.0"

Download java dependencies

1、Download the jar file from the web.

You can download the jar file from MVN Repository or other ways, and put it in the libs directory of the project.

2、use maven

Create a new pom.xml in the project root directory, you can copy this file from the project root directory.

Execute the mvn command to copy dependencies to the target directory. Or copy build.rs from this project, please modify the target directory by yourself.

mvn dependency:copy-dependencies -DoutputDirectory=./libs

Example

    let datasource = jdbc::Builder::new()
        .jdbc_url("jdbc:sqlite::memory:")
        .build()
        .expect("Failed to initialize data source.");

    let conn = datasource.get_connection()?;

    let statement = conn
        .prepare_statement("select username,age from user where id=?")?
        .set_int(1, 1000)?;

    let result = statement.execute_query()?;

    while result.next()? {
        let username = result.get_string(1)?;
        let age = result.get_int(1)?;
        println!("user:{:?} age:{:?}", username, age);
    }

Support type

  • char
  • byte
  • short
  • int
  • long
  • float
  • double
  • boolean
  • String
  • Date
  • Object
  • Blob
  • Clob
  • byte[]
  • BigDecimal
  • AsciiStream
  • BinaryStream
  • CharacterStream

jdbc-rs's People

Contributors

qaqtutu avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.