zoukankan      html  css  js  c++  java
  • JDBCl链接中Statement

    作用:创建的Statement对象执行SQL语句

    (1)对象有Connection对象调用createStatement()方法创建

    (2)有Statement对象调用executeUpdate()方法执行SQL语句

    (3)调用的SQL语句可以是insert delete update但不可以是select



    import com.mysql.jdbc.Statement;
    import java.sql.Connection;
    import java.sql.Driver;
    import java.sql.ResultSet;
    import java.util.Properties;

    /**
    * Created by I am master on 2016/9/29.
    */
    public class finallyjdbc {
    public static void main(String[] args) throws Exception{
    Connection connection=null;
    Statement statement=null;
    //防止抛出的异常导致文件关闭失败
    try {
    Driver driver = new com.mysql.jdbc.Driver();
    String url = "jdbc:mysql://localhost:3306/student";
    Properties properties = new Properties();
    properties.put("user", "root");
    properties.put("password", "root");
    connection = driver.connect(url, properties);
    statement = (Statement) connection.createStatement();
    String query = "insert into studentInfo value('5','小五','17','计算机科学')";
    statement.executeUpdate(query);
    System.out.println("加入成功");
    }catch (Exception e){
    e.printStackTrace();
    }finally {
    try {
    statement.close();
    }catch (Exception e){
    e.printStackTrace();
    }finally {
    connection.close();

    }

    }
    }
    }
  • 相关阅读:
    Servlet学习之http
    初识JDBC-篇四
    初识JDBC-篇三
    正则表达式简单应用3
    正则表达式简单应用2
    正则表达式简单应用1
    反射的简单应用三
    反射的简单应用2
    反射简单的应用
    TCP协议应用--上传文件
  • 原文地址:https://www.cnblogs.com/Hdaydayup/p/5927572.html
Copyright © 2011-2022 走看看