package cn.itcast.jdbc;import java.sql.Connection;import java.sql.DriverManager;import java.sql.SQLException;import java.sql.Statement;/** * @author newcityman * @date 2019/8/12 - 23:40 */public class JDBCDemo02 {public static void main(String[] args) { Connection conn = null; Statement stmt = null; try { Class.forName("com.mysql.jdbc.Driver"); conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/db1", "root", "123"); String sql ="insert into account values(null,'newcityboy','1500.00')"; stmt = conn.createStatement(); int i = stmt.executeUpdate(sql); if(i>0){ System.out.println("添加成功"); }else { System.out.println("添加失败"); } }catch (Exception e){ e.printStackTrace(); }finally{if(stmt!=null){try { stmt.close(); } catch (SQLException e) { e.printStackTrace(); } }if(conn!=null){try { conn.close(); } catch (SQLException e) { e.printStackTrace(); } } } }}
转载于:https://www.cnblogs.com/newcityboy/p/11343382.html
相关资源:JAVA上百实例源码以及开源项目
转载请注明原文地址: https://mac.8miu.com/read-54532.html