jdbc快速入门(java访问数据库)
package com.itcast.jdbc; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import java.sql.Statement; public class JdbcDemo1 { public static void main(String[] args) throws ClassNotFoundException, SQLException { // 1.注册驱动 Class.forName("com.mysql.jdbc.Driver"); // 2.获取数据库连接对象 Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/db1","root","root"); // 3.定义sql语句 String sql = "update student3 set math = 67 where id = 3"; // 4.获取执行sql的对象 Statement stmt = conn.createStatement(); // 5.执行sql int count = stmt.executeUpdate(sql); // 6.处理结果 System.out.println(count); //7.释放资源 stmt.close(); conn.close(); } }
相关推荐
Andrea0 2020-09-18
gaozhennan 2020-08-03
chenjiazhu 2020-07-08
ASoc 2020-11-14
Cherishyuu 2020-08-19
dongtiandeyu 2020-08-18
CoderYYN 2020-08-16
大黑牛 2020-08-15
Dullonjiang 2020-08-11
mcvsyy 2020-08-02
zbcaicai 2020-07-29
AscaryBird 2020-07-27
liulin0 2020-07-26
ldcwang 2020-07-26
helloxusir 2020-07-25
娜娜 2020-07-20
pengpengflyjhp 2020-07-19
点滴技术生活 2020-07-19
人可 2020-07-18