赞
踩
import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import java.sql.Statement; import java.util.Collection; public class demo_jdbc01 { //JDBC的快速入门 public static void main(String[] args) { //获取连接 String url="jdbc:mysql://localhost:3306/jdbc?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8&useSSL=false"; String user="root"; String password="xxxx"; int trys = 0; try { //1. 加载驱动 Class.forName("com.mysql.cj.jdbc.Driver"); //2. 获取连接 Connection conn= DriverManager.getConnection(url,user,password); //3.sql String sql = "UPDATE dept SET money = 2000 WHERE id = 2"; //4.获取执行sql的对象 Statement statement = conn.createStatement(); trys = statement.executeUpdate(sql); //5.释放资源 statement.close(); conn.close(); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } //输出受影响的行数 System.out.println(trys); } } 注意你的database 我的database是jdbc
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。