初学笔记JDBC(有瑕疵)
package com.ddd;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.swing.plaf.synth.SynthSeparatorUI;
public class Day1 {
public static void main(String[] args) throws Exception {
//加载驱动 com.mysql.jdbc.Driver
Class.forName("com.mysql.jdbc.Driver");
//连接数据库
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/web_exam_1", "root", "root");
//创建编辑器
Statement sta = con.createStatement();
String sql="INSERT INto tabe VALUES(1,'小玲')";
int count = sta.executeUpdate(sql);
ResultSet rs = sta.executeQuery("select * from tabe");
while(rs.next()){
System.out.println(rs.getString(2));
}
System.out.println(count);
}
}
持久化:持久化是将程序数据在持久状态和瞬时状态间转换的机制
持久化主要操作:读取 保存 查找 修改 删除
JDBC是用于执行SQL语句的,对多种数据库进行统一访问的Java AP
JDBC API :DriverManager Connection Statement ResultSet