要实现将数据插入数据库表的功能
写好的方法是:
public void savedocument(String name,String path,String university,String index) throws ClassNotFoundException, SQLException{
Connection con;
Statement stmt;
Statement stmt1;
//加载驱动器,下面的代码加载MYSQL驱动器
Class.forName(“com.mysql.jdbc.Driver”);
///注册MYSQL驱动器
//DriverManager.registerDriver(new com.mysql.jdbc.Driver());
//用适当的驱动器连接数据库
String dbUrl = “jdbc:mysql://localhost:3306/moedb?useUnicode=true&characterEncoding=UTF-8”;
String dbUser = “root”;
String dbPwd = “huanghuang”;
//建立数据库连接
con = java.sql.DriverManager.getConnection(dbUrl,dbUser,dbPwd);
//创建一个SQL声明
stmt = con.createStatement();
stmt1 = con.createStatement();
String query = “insert into moe_document(dname,dtime,dtype,dpath,fk_university)”+
“select “””+name+”””,””2014″”,””1″”,”””+path+”””,pk_university from moe_university where unname=”””+university+””””;
String query1=”insert into moe_documenttoindex(fk_document,fk_index)”+”select pk_document,pk_index from moe_document,moe_index where dpath=”””+path+””” and iname=”””+index+””””;
stmt.executeUpdate(query);
stmt1.executeUpdate(query1);
stmt.close();
stmt1.close();
con.close();
}
这样怎么改写dao,service,controller,mapper??在代码中怎么调用方法呢?完全不懂啊!