当前仓库属于关闭状态,部分功能使用受限,详情请查阅 仓库状态说明
2 Star 1 Fork 0

水不要鱼/EasyMySQL
关闭

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
How to use.txt 4.97 KB
一键复制 编辑 原始数据 按行查看 历史
水不要鱼 提交于 2018-05-22 22:19 . 2018-5-22:又一次小更新
*******************************************************************************************************
* Easy MySQL Database Operator v1.0
* author: (FishGoddess)
* development cycle: about 4 hours
* development date: 2017.11.19
* version: 1.2
* why: I am tired of the operations in operating mySQL database...
* So I just simplify them (JDBC mainly) into a tool, which is more easier.
* bugs feedback: As you know, I finished it by myself, and I certainly do some tests.
* But I can't make more cases to test it in just 4 hours.
* So, if you come across some bugs, don't be hesitated!
* give me a feedback or fixed it yourself!
* E-mail: 1149062639@qq.com
*
*******************************************************************************************************
* using steps:
* 1: import the EasyMysql library. (v2.0 version need a AutoMySQL v1.2 or high version)
*
* 2: create a file named DB.properties, then put it in your root directory of your project.
* replace the original infomation with your infomation.
*
* the original information of DB.properties: (without =)
* (you can copy these words to DB.properties.)
===================================
# Mysql url (Necessary)
url=jdbc:mysql://127.0.0.1:3306/java?useSSL=false
# username (Necessary)
username=root
# password (Necessary)
password=1997
===================================
* you can update this information by invoking DBManager.update().
* more parameters infomation in params.md! Or you could find them in dpcp website!
*
* 3: now you can use the methods in class DBWorker
* At first, you should invoke DBWorker dbWorker = DBManager.getDBWorker(); to connect to database!
* After you use, you should release resources by invoking DBWorker.sleep()!
* 1: insert data
* // insert a new book in database...
* dbWorker.insert(book);
*
* 2: delete data
* // delete the row in goods_cates, which cate_name is "..."
* dbWorker.delete("goods_cates", "cate_name = \"...\"");
*
* 3: update data
* // update oldBook to newBook
* int count = dbWorker.update(oldBook, newBook);
* System.out.println(count); // retun the count of effected rows
*
* 4: query data
* // query one row in goods_cates, which id is 4
* List<String> list = dbWorker.queryStrings("goods_cates", "id = 4");
* //List<Map> list = dbWorker.queryMaps("goods_cates", "id = 4");
* for (String s : list) // for (Map m : list)
* {
* System.out.println(s); // print the string obtained
* }
* // find data by targetBook, then return book object
* com.fish.Book book = dbWorker.query(targetBook, com.fish.Book.class);
*
* 5: save a whole data table to disk
* // this will put the whole table in a file and store to disk.
* // for example, save test table as test.txt and store to Z:/
* dbWorker.putTableInFile("test", "Z:/test.txt");
*
* here is some common operation, if you need more API, get them in the javadoc!
*
*******************************************************************************************************
// an example, it can run immediately, but you may rename your code file to Examples.java
package com.fish.core;
import java.util.List;
public class Examples
{
public static void main(String[] args) throws Exception
{
// set config...
DBManager.init(new File("DB.properties"));
// auto commit ==> default is true
//DBManager.setAutoCommit(false);
// connect to database...
DBWorker dbWorker = DBManager.getDBWorker();
com.fish.Book book = new com.fish.Book();
book.setName("奇异人生");
book.setPrice(68);
// insert a new book in database...
//dbWorker.insert(book);
// put whole table in a file...
//dbWorker.putTableInFile("book", "Z:/book.txt");
// query a book...
book = dbWorker.query(book, com.fish.Book.class);
System.out.println(book);
List<Object> books = new ArrayList<>();
books.add(new Book("蒙太奇手法", 129));
books.add(new Book("音乐素养与教养", 72));
books.add(new Book("中国为什么这么强大", 999));
books.add(new Book("看世界", 69));
books.add(new Book("读者", 12));
// insert many books...
dbWorker.insertAll(books.toArray());
// batch
dbWorker.workBatch(new String[] {
"INSERT INTO book(name, price) VALUES('论三国', 23), ('孙子兵法', 24);",
"INSERT INTO book(name, price) VALUE('世界之大宇宙之小', 89);"
});
// release resources and commit transaction...
dbWorker.sleep();
}
}
*******************************************************************************************************
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/FishGoddess/EasyMySQL.git
git@gitee.com:FishGoddess/EasyMySQL.git
FishGoddess
EasyMySQL
EasyMySQL
maven

搜索帮助