zoukankan      html  css  js  c++  java
  • 传统数据库连接方式

    package cn.jiaying.demo;

    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.PreparedStatement;

    public class JDBCdemo {
    public static void main(String[] args) throws Exception {
    fun1();

    }
    //更新表格中的数据 简单的替换
    public static void fun1() throws Exception{
    Class.forName("com.mysql.jdbc.Driver"); // Class.forname("com.mysql.jdbc.Driver")驱动程序
    String url="jdbc:mysql://localhost:3306/day36";//获得数据库连接对象
    String username="root";//获得数据库连接对象
    String password="root";//获得数据库连接对象
    Connection con=DriverManager.getConnection(url,username,password);
    //DriverManager类 数据库 连接拥有一个静态方法 getConnection() DriverManager.getConnection();获得连接对象
    String sql="UPDATE student SET name=?, sex=?,sno=?,address=?,class=? WHERE id=?";
    PreparedStatement pst=con.prepareStatement(sql);
    pst.setObject(1,"代我向西贝问好");
    pst.setObject(2,"男");
    pst.setObject(3,2015);
    pst.setObject(4,165);
    pst.setObject(5,2015165);
    pst.setObject(6,1);
    //executeUpdate() 执行更新
    int s=pst.executeUpdate();
    System.out.println(s);
    pst.close();
    con.close();
    }
    }

  • 相关阅读:
    nginx解决跨域问题
    SSM整合相关试题
    SSM整合案例--用户登录
    非法用户登录拦截
    SpringMVC拦截器和数据校验
    SpringMVC文件上传
    SpringMVC异常处理
    SpringMVC方法的返回值类型和自动装配
    SpringMVC
    spring和mybatis整合
  • 原文地址:https://www.cnblogs.com/Fisherman13/p/10437372.html
Copyright © 2011-2022 走看看