本文章主要介绍了jdbc入门 连接mysql执行简单语句,具有不错的的参考价值,希望对您有所帮助,如解说有误或未考虑完全的地方,请您留言指出,谢谢!
package cn.itcast.jdbc;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
/**
* @Author: Zhang
* @Description:JDBC快速入门
* @Date: Created in 15:18 2020/12/27
* @Modified By:
*/
public class JdbcDemo1 {
public static void main(String[] args) throws Exception {
//1.导入jar包
//2.注册驱动
Class.forName("com.mysql.jdbc.Driver");
//3.获取数据库的连接对象
Connection conn = DriverManager.getConnection("jdbc:mysql://doitedu01:3306/test","root","ABC123abc.123");
//4.定义sql语句
String sql = "update student set gender = 'w' where id = '201901' ";
//5.获取执行sql的对象Statement
Statement statement = conn.createStatement();
//6.执行sql
int count = statement.executeUpdate(sql);
//7.处理结果
System.out.println(count);
//8.释放资源
statement.close();
conn.close();
}
}
原创文章,作者:506227337,如若转载,请注明出处:https://blog.ytso.com/228225.html