jdbc快速入门(java访问数据库)
时间:2021-07-01 10:21:17
帮助过:5人阅读
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();
}
}
jdbc快速入门(java访问数据库)
标签:获取 入门 otf 取数 oid com statement rman system