Javajavaweb mysql的增删改查参考文章:https://blog.csdn.net/qq_40718312/article/details/95489257 maven jar包查询地址:https://search.maven.org/ 引入mysql jar mysql mysql-connector-java 5.1.47 增 package net.jdbc.test; impo作者王明昌发布时间2019-10-16最后更新2019-10-19文章目录引入mysql jar增删改查参考文章:https://blog.csdn.net/qq_40718312/article/details/95489257maven jar包查询地址:https://search.maven.org/引入mysql jar复制 mysql mysql-connector-java 5.1.47 增复制package net.jdbc.test; import java.sql.*; public class Add { public static void main(String[] args) { ResultSet rs = null; PreparedStatement statement = null; Connection connection = null; try { //1.加载驱动 Class.forName("com.mysql.jdbc.Driver"); //2.创建连接 connection = DriverManager.getConnection ("jdbc:mysql://120.78.193.246:3306/jdd?useSSL=true&" + "characterEncoding=utf-8&user=" + "jdd&password=fEh4mJFPRG87z3k4"); System.out.println("创建连接成功"); //3.写sql String sql = "insert into bookinfo(book_name,price,public_date,store) values(?,?,?,?)"; //4.得到statement对象 statement = connection.prepareStatement(sql); //5.执行sql得到结果集 statement = connection.prepareStatement(sql); //6.处理结果集,插入数据 statement.setString(1, "Rose"); statement.setString(2, "123"); statement.setString(3, "2019-02-01"); statement.setString(4, "1"); statement.executeUpdate(); System.out.println("插入成功!"); //7.关闭资源 } catch (Exception e) { e.printStackTrace(); } finally { if (rs != null) { try { rs.close(); } catch (SQLException e) { e.printStackTrace(); } } if (statement != null) { try { statement.close(); } catch (SQLException e) { e.printStackTrace(); } } if (connection != null) { try { connection.close(); } catch (SQLException e) { e.printStackTrace(); } } } } } 删复制package net.jdbc.test; import java.sql.*; public class Del { public static void main(String[] args) { ResultSet rs = null; PreparedStatement statement = null; Connection connection = null; try { //1.加载驱动 Class.forName("com.mysql.jdbc.Driver"); //2.创建连接 connection = DriverManager.getConnection ("jdbc:mysql://120.78.193.246:3306/jdd?useSSL=true&" + "characterEncoding=utf-8&user=" + "jdd&password=fEh4mJFPRG87z3k4"); System.out.println("创建连接成功"); //3.写sql String sql = "delete from bookinfo where book_id=?"; //4.得到statement对象 statement = connection.prepareStatement(sql); //5.执行sql得到结果集 statement.setInt(1,2); statement.executeUpdate(); System.out.println("删除成功!"); //7.关闭资源 } catch (Exception e) { e.printStackTrace(); } finally { if (rs != null) { try { rs.close(); } catch (SQLException e) { e.printStackTrace(); } } if (statement != null) { try { statement.close(); } catch (SQLException e) { e.printStackTrace(); } } if (connection != null) { try { connection.close(); } catch (SQLException e) { e.printStackTrace(); } } } } } 改复制package net.jdbc.test; import java.sql.*; public class Update { public static void main(String[] args) { ResultSet rs = null; PreparedStatement statement = null; Connection connection = null; try { //1.加载驱动 Class.forName("com.mysql.jdbc.Driver"); //2.创建连接 connection = DriverManager.getConnection ("jdbc:mysql://120.78.193.246:3306/jdd?useSSL=true&" + "characterEncoding=utf-8&user=" + "jdd&password=fEh4mJFPRG87z3k4"); System.out.println("创建连接成功"); //3.写sql String sql = "update bookinfo set book_name=?,store=? where book_id=?"; //4.得到statement对象 statement = connection.prepareStatement(sql); //5.执行sql得到结果集 statement = connection.prepareStatement(sql); //6.处理结果集,插入数据 statement.setString(1,"abc"); statement.setString(2,"789"); statement.setInt(3,1); statement.executeUpdate(); System.out.println("修改成功!"); //7.关闭资源 } catch (Exception e) { e.printStackTrace(); } finally { if (rs != null) { try { rs.close(); } catch (SQLException e) { e.printStackTrace(); } } if (statement != null) { try { statement.close(); } catch (SQLException e) { e.printStackTrace(); } } if (connection != null) { try { connection.close(); } catch (SQLException e) { e.printStackTrace(); } } } } } 查复制package net.jdbc.test; import java.math.BigDecimal; import java.sql.*; public class Select { //数据库url、用户名和密码 static final String DB_URL="jdbc:mysql://120.78.193.246:3306/jdd?"; static final String USER="jdd"; static final String PASS="fEh4mJFPRG87z3k4"; public static void main(String[] args) { try { //1、注册JDBC驱动 Class.forName("com.mysql.jdbc.Driver"); //2、获取数据库连接 Connection connection = DriverManager.getConnection(DB_URL, USER, PASS); //3、操作数据库 Statement statement = connection.createStatement();//获取操作数据库的对象 String sql="select * from bookinfo"; ResultSet resultSet = statement.executeQuery(sql);//执行sql,获取结果集 while(resultSet.next()){ //遍历结果集,取出数据 int book_id = resultSet.getInt("book_id"); String book_name = resultSet.getString("book_name"); BigDecimal price = resultSet.getBigDecimal("price"); Date public_date = resultSet.getDate("public_date"); String store = resultSet.getString("store"); //输出数据 System.out.print("图书编号:"+book_id); System.out.print(",图书名称:"+book_name); System.out.print(",价格"+price); System.out.print(",出版日期"+public_date); System.out.print(",库存"+store); System.out.println(); } //4、关闭结果集、数据库操作对象、数据库连接 resultSet.close(); statement.close(); connection.close(); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch(SQLException e){ e.printStackTrace(); } catch(Exception e){ e.printStackTrace(); } } }
2020-02-01ssm框架搭建整体结构  基本的配置 pom.xml 4.0.0 con.zf ssm2 1.0-SNAPSHOT jar ssm2 Maven Webapp http://www.example.com UTF
2019-11-12javaweb开发 idea ssm开发(一)创建项目 新建一个空白项目 创建父工程 选中Maven 不要勾选任何框架->com.zf.edu common-parent  删除src 添加部分代码  创建model子工程   新建一个m
2019-11-25javaSSM学习第一天(mybatis)mybatis mybatis是持久层框架,封装了jdbc mybatis入门 官网:https://mybatis.org/mybatis-3/zh/index.html 依赖: org.mybat
2019-09-28Javaweb form提交数据http://localhost:8080/webTest/show.jsp?uname=%E5%B0%8F%E6%98%8E&upwd=121&uage=12&uhobbies=%E7%BE%BD%
2019-11-13javaweb开发 idea ssm开发(二)dao整合mybatis 添加依赖 写公共接口 继承接口 在子类中引入父类  引入依赖model  dao层创建mapper      service 依赖dao 添加依赖  创建 
2020-03-15Java入门基础整理(一)hello 执行 javac Hello.java 生成 Hello.class // Hello 要与文件名相同 public class Hello{ // 程序执行的起点 public stat