import java.sql.Statement;
/**
* @author facty
* @create 2021-21-30 19:21
*/
public class JDBCDemo {
public static void main(String[] args) throws Exception{
//1.注册驱动
// Class.forName("com.mysql.jdbc.Driver");
//2.获取连接
//url还有种默认写法String url ="jdbc:mysql:///db1?useSSL=false" ;
String url ="jdbc:mysql://127.0.0.1:3306/db1" ;
String username = "root";
String password = "1234";
//3.定义sql
String sql = "update tb_user set password = '1234' where id = 3";
//4.获取执行sql的对象 Statement
Statement stmt = conn.createStatement();
//5.执行sql
//对于DDL语言和DML语言用如下executeUpdate即可,其他用executeQuery
// 且返回结果用ResultSet类来接收(下面用int接收改变的表行数)
int count = stmt.executeUpdate(sql);
//6.处理结果
//如果DQL语句则要循环打印出表(如姓名,工资,id等)
System.out.println(count);
//7.释放资源
// 如果是DQL语句还要关闭ResultSet对象,
stmt.close();
conn.close();
}
}
JDBC学习总结
2021/12/1 13:08:24