开发者

how to create database using java code?

开发者 https://www.devze.com 2023-03-08 16:52 出处:网络
I want to create a d开发者_开发知识库atabase using java code, I have the database script file, I will read in a string and I will execute it but I want to know if I can use executequery or executeupda

I want to create a d开发者_开发知识库atabase using java code, I have the database script file, I will read in a string and I will execute it but I want to know if I can use executequery or executeupdate??? and if this method is right or there is another one???


The method signature for the executeUpdate method of the Statement interface is:

int executeUpdate(String sql)
                  throws SQLException

executeUpdate executes the given SQL statement, which may be an INSERT, UPDATE, or DELETE statement or an SQL statement that returns nothing, such as an SQL DDL statement.

So to define a table or define an index, you would pass the SQL string to the executeUpdate method.

You can only execute one SQL statement at a time using the executeUpdate method, so if you're reading a file with more than one SQL statement, you'll have to parse the file and execute each SQL statement, one at a time.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号