import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
public class Jdbc1 {
public static void main(String[] args) throws Exception{
//1> 加载 mysql驱动
// 加载mysql 数据库的具体代码实现
Class.forName(“com.mysql.jdbc.Driver”);
//mysql
//jdbc:mysql://hostname:port/databasename
//oracle
//jdbc:oracle:thin:@hostname:port:databasename
//mysql 数据库连接信息
//1> 主机 IP 地址
//2> mysql 应用的具体的固定端号3306
// 主机 IP 地址 + 固定端号口3306 == 百分之百确定的是mysql
//3> mysql 的 数据库名字 class_1839
//指定连接 中文编码参数 "?useUnicode=true&characterEncoding=utf-8
//4> mysql 的用户 root
//5> mysql 用户对应的密码123456
String url = "jdbc:mysql://localhost:3306/class_1839"+"?useUnicode=true&characterEncoding=utf-8";
String user = "root";
String password = "123456";
java.sql.Connection connection = DriverManager.getConnection(url,user,password);
Statement statement = connection.createStatement();
//1>查询学生的所有信息
//ResultSet 结果集
// ResultSet rs = statement.executeQuery(“select * from student”);
//
// while (rs.next()){
// int id = rs.getInt(1);
// String name = rs.getString(2);
// int age = rs.getInt(3);
// System.out.println(id +"\t" +name+"\t"+age+"\t");
// }
//2> 新增学生信息
//4 李四 19
//("插入信息的sql语句")
// statement.execute(“insert into student(id,name,age) values(4,‘李四’,19)”);
// statement.execute(“insert into student(id,name,age) values(5,‘小老弟’,40)”);
// statement.execute(“insert into student(id,name,age) values(6,‘小二弟’,10)”);
// statement.execute(“insert into student(id,name,age) values(7,‘小连弟’,13)”);
//3> 修改学号为 7 的年龄为22
// statement.execute(“update student set age='22’where id=7”);
//4> 删除学号为5的学生信息
// statement.execute(“delete from student where id=5”);
//5> 查询年龄等于19的所有学生信息遍历出来
//ResultSet 结果集
// ResultSet rs = statement.executeQuery(“select * from student where age =19”);
//
// while (rs.next()){
// int id = rs.getInt(1);
// String name = rs.getString(2);
// int age = rs.getInt(3);
// System.out.println(id +"\t" +name+"\t"+age+"\t");
// }
}
}