RT
马上下班五一了, @zz210891470 你这样@ 我不好23333 我写在这里吧,如果还有其他人问的话, 很简单的。
public class Db_CREATE { public static void main(String[] args) { DruidPlugin druidPlugin = new DruidPlugin( "jdbc:mysql://127.0.0.1:3306/information_schema?characterEncoding=UTF-8&autoReconnect=true&failOverReadOnly=false&zeroDateTimeBehavior=convertToNull", "root", "").set(1, 1, 100); ActiveRecordPlugin arp = new ActiveRecordPlugin(druidPlugin); // 启动管理库 druidPlugin.start(); arp.start(); String name = "test_1"; // 建库 Db.update("CREATE DATABASE " + name); // 启动业务库 DruidPlugin druidPluginTest = new DruidPlugin("jdbc:mysql://127.0.0.1:3306/" + name + "?characterEncoding=UTF-8&autoReconnect=true&failOverReadOnly=false&zeroDateTimeBehavior=convertToNull", "root", "").set(1, 1, 100); ActiveRecordPlugin arpTest = new ActiveRecordPlugin(name, druidPluginTest); druidPluginTest.start(); arpTest.start(); // 建表 DbPro testDb = Db.use(name); testDb.update( "CREATE TABLE `a` ( `id` int NOT NULL AUTO_INCREMENT , `xx` varchar(255) NULL , PRIMARY KEY (`id`) ) "); // 写入数据 testDb.update("INSERT INTO `a` (`xx`) VALUES ('xxxxx')"); // 查询 List<Record> list = testDb.find("SELECT * FROM `a` LIMIT 100"); System.out.println(list.toString()); arpTest.stop(); druidPluginTest.stop(); arp.stop(); druidPlugin.stop(); } }
注意要使用 有权限的账户 才能建库, 比如 root 账户。 有用就点个赞