sql脚本生成表的操作实例
print.out自己写的工具类相当于system.out.println();
properties properties = new properties();
properties.load(resources.getresourceasstream("propertiesname"));
print.out(properties.getproperty("status"));
if(properties.get("status").equals("0")) {
string username = properties.getproperty("jdbc.user");
string password = properties.getproperty("jdbc.password");
string host = properties.getproperty("jdbc.host");
string port = properties.getproperty("jdbc.port");
string importdatabasename = properties.getproperty("jdbc.importdatabasename");
//使用要导入sql脚本的位置
string file = resources.getresourceurl("powermanager.sql").getfile();
string desfile = file.substring(1);
stringbuilder sb = new stringbuilder();
string logincommand = new stringbuffer()
.append("mysql -u")
.append(username)
.append(" -p")
.append(password)
.append(" -h")
.append(host)
.append(" -p")
.append(port)
.tostring();
string dbcommand = new stringbuffer()
.append("use ")
.append(importdatabasename)
.tostring();
//第三步:拼接要导入的sql脚本
string sqlcommand = new stringbuffer()
.append("source ")
.append(desfile)
.tostring();
string[] str = new string[] {logincommand,dbcommand,sqlcommand};
print.out("正在初始化...");
process exec = runtime.getruntime().exec(str[0]);
outputstream outputstream = exec.getoutputstream();
outputstreamwriter writer = new outputstreamwriter(outputstream);
writer.write(str[1]+"\r\n"+str[2]);
writer.flush();
writer.close();
outputstream.close();
//修改properties配置文件的内容
properties.setproperty("status", "1");
fileoutputstream fos = new fileoutputstream(resources.getresourceurl("config/db.properties").getfile());
//保存修改的信息
properties.store(fos, "数据库生成");
thread.sleep(10000);
print.out("数据库生成...");
/*
* 以上结束了动态生成表的sql脚本
*/
上一篇: promise中的.then()方法