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();

    }

    }
    }
    }
  • 相关阅读:
    hping3 DDOS泛洪攻击
    如何利用kali破解密码
    python 字典数据类型day05
    Cisco Packet Tracer思科模拟器汉化本
    菜鸟入坑pythonday04列表
    python菜鸟入坑day02
    python运行的第一个脚本菜鸟篇
    python整个安装过程+环境变量
    菜鸟入坑python第一节
    01、python基础知识
  • 原文地址:https://www.cnblogs.com/Hdaydayup/p/5927572.html
Copyright © 2011-2022 走看看