在createstatement()和execute()中传递SQL查询有什么区别?

时间:2018-02-19 02:08:42

标签: java jdbc

In both cases同样的事情发生了(插入/操纵数据)。但内部会发生什么?

在execute()中传递查询:

        Class.forName("com.mysql.jdbc.Driver");

        Connection con= DriverManager.getConnection("jdbc:mysql://localhost:3306/mysql","root","dinga");

        String str="insert into student values(10,'abc',100)";

        Statement stmt=con.createStatement();

        stmt.execute(str); //Passing query in execute()

        System.out.println("Data inserted successfully");

在CreateStatement()

中传递查询
        Class.forName("com.mysql.jdbc.Driver");

        Connection con= DriverManager.getConnection("jdbc:mysql://localhost:3306/mysql","root","dinga");

        String str="insert into student values(10,'abc',100)";

        Statement stmt=con.createStatement(str);//Passing Query in createStatement()

        stmt.execute();

        System.out.println("Data inserted successfully");

1 个答案:

答案 0 :(得分:-3)

除了这种情况下的可读性之外没有区别:P