# newbie-jdbc
**Repository Path**: chyxion/newbie-jdbc
## Basic Information
- **Project Name**: newbie-jdbc
- **Description**: Newbie JDBC
- **Primary Language**: Java
- **License**: MIT
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 22
- **Forks**: 6
- **Created**: 2016-04-18
- **Last Updated**: 2024-03-08
## Categories & Tags
**Categories**: database-dev
**Tags**: None
## README
#Newbie JDBC
**Newbie JDBC** is a simple JDBC tool, It supports array parameters expanding, connection sharing, transaction, pagination and so on.
## Usage
### Add Maven Dependency
```xml
me.chyxionnewbie-jdbc0.0.2-RELEASE
```
### Use In Code
#### Create Newbie JDBC Object
```java
// init datasource, here use DruidDataSource as demo
DruidDataSource datasource = null;
datasource = new DruidDataSource();
datasource.setUrl("jdbc:mysql://127.0.0.1/demo");
datasource.setUsername("root");
datasource.setPassword("password");
datasource.init();
// create NewbieJdbc object
NewbieJdbc jdbc = new NewbieJdbcImpl(datasource);
```
#### Basic Query
```java
// count of users
int count = jdbc.findValue(
"select count(1) from users");
// find name of user id is 2008110101
String name = jdbc.findValue(
"select name from users where id = ?",
"2008110101");
// find names of user id is 101 or 102
// 0. array as params
List names = jdbc.listValue(
"select name from users where id in (?)",
"101", "102");
// 1. collection as params
names = jdbc.listValue(
"select name from users where id in (?)",
Arrays.asList("101", "102"));
// 2. map as params
Map params =
new HashMap();
params.put("id", Arrays.asList("101", "102"));
// or:
// params.put("id", new String[] {"101", "102"});
names = jdbc.listValue(
"select name from users where id in (:id)",
params);
// find user of id is 101
Map mapUser = jdbc.findMap(
"select id, name, gender from users where id = ?", "101");
// list users of age is 24
List