All Projects → ZhaoLizz → JDBCManager

ZhaoLizz / JDBCManager

Licence: other
一款操作数据库的小工具

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to JDBCManager

NiuBi
👊 一个Java文件也能干大事系列
Stars: ✭ 34 (+161.54%)
Mutual labels:  jdbc
java-notes
Complete Java Note for colleges in Nepal.
Stars: ✭ 30 (+130.77%)
Mutual labels:  jdbc
komapper
Kotlin SQL Mapper
Stars: ✭ 28 (+115.38%)
Mutual labels:  jdbc
table2pojo
Generate POJOs for database table/columns
Stars: ✭ 16 (+23.08%)
Mutual labels:  jdbc
spwrap
Simple Stored Procedure call wrapper with no framework dependencies.
Stars: ✭ 24 (+84.62%)
Mutual labels:  jdbc
wasp
WASP is a framework to build complex real time big data applications. It relies on a kind of Kappa/Lambda architecture mainly leveraging Kafka and Spark. If you need to ingest huge amount of heterogeneous data and analyze them through complex pipelines, this is the framework for you.
Stars: ✭ 19 (+46.15%)
Mutual labels:  jdbc
soda-for-java
SODA (Simple Oracle Document Access) for Java is an Oracle library for writing Java apps that work with JSON (and not only JSON!) in the Oracle Database. SODA allows your Java app to use the Oracle Database as a NoSQL document store.
Stars: ✭ 61 (+369.23%)
Mutual labels:  jdbc
itstack-naive-chat-server
💞 《服务端》| 服务端同样使用Netty4.x作为socket的通信框架,同时在服务端使用Layui作为管理后台的页面,并且我们的服务端采用偏向于DDD领域驱动设计的方式与Netty集合,以此来达到我们的框架结构整洁干净易于扩展。同时我们的通信协议也是在服务端进行定义的,并对外提供可引入的Jar包,这样来保证客户端与服务端共同协议下进行通信。
Stars: ✭ 21 (+61.54%)
Mutual labels:  jdbc
DBISProject
Library Management System using Java and MySQL
Stars: ✭ 27 (+107.69%)
Mutual labels:  jdbc
hive-jdbc-driver
An alternative to the "hive standalone" jar for connecting Java applications to Apache Hive via JDBC
Stars: ✭ 31 (+138.46%)
Mutual labels:  jdbc
zuul-route-jdbc-spring-cloud-starter
No description or website provided.
Stars: ✭ 23 (+76.92%)
Mutual labels:  jdbc
Neo
Orm框架:基于ActiveRecord思想开发的至简化的java的Orm框架
Stars: ✭ 35 (+169.23%)
Mutual labels:  jdbc
dogETL
A lib to transform data from jdbc,csv,json to ecah other.
Stars: ✭ 15 (+15.38%)
Mutual labels:  jdbc
tamer
Standalone alternatives to Kafka Connect Connectors
Stars: ✭ 42 (+223.08%)
Mutual labels:  jdbc
HiveJdbcStorageHandler
No description or website provided.
Stars: ✭ 21 (+61.54%)
Mutual labels:  jdbc
eth-jdbc-connector
Ethereum JDBC driver implements a pure java, type 4 JDBC driver that executes SQL queries on Ethereum Blockchain.
Stars: ✭ 19 (+46.15%)
Mutual labels:  jdbc
java
📚 Recursos para aprender Java
Stars: ✭ 31 (+138.46%)
Mutual labels:  jdbc
sqlite-jna
Java wrapper and Jdbc driver for SQLite using JNA or Bridj or JNR or JNI or JavaCPP.
Stars: ✭ 20 (+53.85%)
Mutual labels:  jdbc
database-metadata-bind
A library for binding information from java.sql.DatabaseMetadata
Stars: ✭ 17 (+30.77%)
Mutual labels:  jdbc
implyr
SQL backend to dplyr for Impala
Stars: ✭ 74 (+469.23%)
Mutual labels:  jdbc

JDBCManager使用文档

介绍

对sqlserver的jdbc增删改查操作进行的封装。使用了回调和反射机制。使操作数据库更加简便快乐。

导入

clone项目后,导入JDBCDao,JDBCHelper,JDBCObject,JDBCSetting四个类即可

初始化

JDBCSetting类中修改常量URL,USERNAME,PASSWORD为自己连接sqlserver数据库的参数

public class JDBCSetting {
    static final String DRIVER = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
    static final String URL = "jdbc:sqlserver://localhost:1433;DatabaseName=Test";
    static final String USERNAME = "your_username";
    static final String PASSWORD = "your_password";
}

使用方法

  1. 首先创建二维表的映射JavaBean类,类成员变量的名字要和二维表中列名相同,类名要和表名相同,成员变量类型和二维表中定义的类型一致
  2. 创建getter和setter方法
  3. 继承自JDBCObject
public class Student extends JDBCObject {
    private String student_no;
    private String student_pw;
    private String student_name;
    private String student_target;
    private String student_special;
    private int student_is_manager = 0;     //默认值为0

    public String getStudent_no() {
        return student_no;
    }

    public void setStudent_no(String student_no) {
        this.student_no = student_no;
    }

    public String getStudent_name() {
        return student_name;
    }

    public void setStudent_name(String student_name) {
        this.student_name = student_name;
    }

    public String getStudent_pw() {
        return student_pw;
    }

    public void setStudent_pw(String student_pw) {
        this.student_pw = student_pw;
    }

    public String getStudent_target() {
        return student_target;
    }

    public void setStudent_target(String student_target) {
        this.student_target = student_target;
    }

    public String getStudent_special() {
        return student_special;
    }

    public void setStudent_special(String student_special) {
        this.student_special = student_special;
    }

    public int getStudent_is_manager() {
        return student_is_manager;
    }

    public void setStudent_is_manager(int student_is_manager) {
        this.student_is_manager = student_is_manager;
    }

    @Override
    public String toString() {
        return "Student{" +
                "student_no='" + student_no + '\'' +
                ", student_pw='" + student_pw + '\'' +
                ", student_name='" + student_name + '\'' +
                ", student_target='" + student_target + '\'' +
                ", student_special='" + student_special + '\'' +
                ", student_is_manager=" + student_is_manager +
                '}';
    }
}

映射参照的关系型数据库如下:

添加数据

  1. 创建数据库二维表映射的JavaBean对象,set各成员变量要添加的值
  2. 调用save()方法
    Student student = new Student();
    student.setStudent_no(username);
    student.setStudent_pw(password);
    student.setStudent_target(target);
    student.setStudent_name(studentName);
    student.setStudent_special(special);
    student.save(new JDBCDao.SaveListerner() {
        @Override
        public void onSucceed() {
            //TODO
        }
    
        @Override
        public void onFailed(Exception e) {
            e.printStackTrace();
        }
    });

删除数据

  1. 把删除条件添加进入javabean对象
  2. 调用delete()方法
//删除名字为Morty,专业为 Science的学生数据
Student student = new Student();
student.setStudent_name("Morty");
student.setStudent_special("Science");
student.delete(new JDBCDao.DeleteListener() {
            @Override
            public void onSucceed() {

            }

            @Override
            public void onFailed(Exception e) {
                e.printStackTrace();
            }
        });

修改数据

  • 修改数据需要两个javabean对象
    • 第一个对象用于设置修改后的值
    • 第二个对象作为查询条件,用于在数据库中找到需要修改的那条数据
        //查找名字为Rick,专业为Science的学生,把他的名字修改为Morty
        Student condition = new Student();
        condition.setStudent_name("Rick");
        condition.setStudent_special("Science");

        Student student = new Student();
        student.setStudent_name("Morty");
        student.update(condition, new JDBCDao.UpdateListener() {
            @Override
            public void onSucceed() {

            }

            @Override
            public void onFailed(Exception e) {
                e.printStackTrace();
            }
        });

查询数据

  • 查询方法会把数据库查询结果映射为javabean类的一个List对象
  1. 为javabean对象设置查询条件
  2. 调用query方法,传入javabean类的类型信息参数
        //查询名字为 Rick, 专业为Science的学生信息
        Student student = new Student();
        student.setStudent_name("Rick");
        student.setStudent_special("Science");
        student.query(Student.class, new JDBCDao.QueryListener<Student>() {
            @Override
            public void onSucceed(List<Student> result) {
                for (Student s : result) {
                    System.out.println(s);
                }
            }

            @Override
            public void onFailed(Exception e) {
                e.printStackTrace();
            }
        });     

释放连接

JDBCHelper.getInstance().releaseConn();

致读者

鄙人才疏学浅,难免有bug和疏漏。欢迎大家提PullRequest和Issue。项目用于交流,共同学习共同进步。

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].