代码拉取完成,页面将自动刷新
*******************************************************************************************************
* 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();
}
}
*******************************************************************************************************
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。