2023年8月3日发(作者:)
java数据库update变量_替换.sql脚本中的变量并使⽤JavaJDBC运⾏它们我只使⽤Warework.这是⼀个很⼤的JAR,但我认为它可以满⾜您的需求.我会告诉你它是如何⼯作的:1-在项⽬的源⽂件夹中创建此⽬录结构:/META-INF/system/statement/sql2-在“/ META-INF / system”⽬录中,使⽤以下内容创建名为“”的⽂件:在此⽂件中,将参数值替换为与数据库连接所需的值.保持“connect-on-create”等于“true”.3-在./ META-INF / system / statement / sql“⽬录中编写.sql脚本.您可以编写这样的SELECT语句(每个⽂件⼀个语句):找到-ECT * FROM HOME_USERS A WHERE = ${USER_ID}和UPDATE这样的语句(每个⽂件⼀个或多个语句):创建-ERT INTO HOME_USERS (ID, NAME) VALUES (${USER_ID}, ${USER_NAME});INSERT INTO ACTIVE_USERS (ID) VALUES (${USER_ID});4-要连接数据库,请执⾏以下操作:// "" must be any class of your project (the same project where /META-INF/system directory exists).// Do not change "full" and "relational-database" strings.// If you change "system" for "test", then the directory will be /META-INF/iew ddbb = (RDBMSView) Template(, "full", "system").getObject("relational-database");// Connect with the t();5-从.sql⽂件运⾏SELECT语句,如下所⽰:// Values for variables in the SELECT ble values = new Hashtable();// Set variables to filter the ("USER_ID", new Integer(8375));// Read '/META-INF/system/statement/sql/', replace variables and run.// -1 values are for pagination (first -1 is the page, second -1 is the max rows per page).ResultSet result = (ResultSet) eQueryByName("find-user", values, -1, -1);6-从.sql⽂件运⾏UPDATE语句,如下所⽰:// Values for variables in the UPDATE ble values = new Hashtable();// Set variables for the update ("USER_ID", new Integer(3));("USER_NAME", "Oompa Loompa");// Read '/META-INF/system/statement/sql/', replace variables and run.// ';' is the character that separates each eUpdateByName("create-user", values, new Character(';'));RDBMSView类提供了这些⽅法以及connect / disconnect,commit,rollback,…您还可以直接从String对象运⾏语句.
2023年8月3日发(作者:)
java数据库update变量_替换.sql脚本中的变量并使⽤JavaJDBC运⾏它们我只使⽤Warework.这是⼀个很⼤的JAR,但我认为它可以满⾜您的需求.我会告诉你它是如何⼯作的:1-在项⽬的源⽂件夹中创建此⽬录结构:/META-INF/system/statement/sql2-在“/ META-INF / system”⽬录中,使⽤以下内容创建名为“”的⽂件:在此⽂件中,将参数值替换为与数据库连接所需的值.保持“connect-on-create”等于“true”.3-在./ META-INF / system / statement / sql“⽬录中编写.sql脚本.您可以编写这样的SELECT语句(每个⽂件⼀个语句):找到-ECT * FROM HOME_USERS A WHERE = ${USER_ID}和UPDATE这样的语句(每个⽂件⼀个或多个语句):创建-ERT INTO HOME_USERS (ID, NAME) VALUES (${USER_ID}, ${USER_NAME});INSERT INTO ACTIVE_USERS (ID) VALUES (${USER_ID});4-要连接数据库,请执⾏以下操作:// "" must be any class of your project (the same project where /META-INF/system directory exists).// Do not change "full" and "relational-database" strings.// If you change "system" for "test", then the directory will be /META-INF/iew ddbb = (RDBMSView) Template(, "full", "system").getObject("relational-database");// Connect with the t();5-从.sql⽂件运⾏SELECT语句,如下所⽰:// Values for variables in the SELECT ble values = new Hashtable();// Set variables to filter the ("USER_ID", new Integer(8375));// Read '/META-INF/system/statement/sql/', replace variables and run.// -1 values are for pagination (first -1 is the page, second -1 is the max rows per page).ResultSet result = (ResultSet) eQueryByName("find-user", values, -1, -1);6-从.sql⽂件运⾏UPDATE语句,如下所⽰:// Values for variables in the UPDATE ble values = new Hashtable();// Set variables for the update ("USER_ID", new Integer(3));("USER_NAME", "Oompa Loompa");// Read '/META-INF/system/statement/sql/', replace variables and run.// ';' is the character that separates each eUpdateByName("create-user", values, new Character(';'));RDBMSView类提供了这些⽅法以及connect / disconnect,commit,rollback,…您还可以直接从String对象运⾏语句.
发布评论