- JAVA通过jdbc与mysql连接
- Mysql执行传来的sql语句
- Jdbc返回mysql执行结果
- Java处理返回结果
//加载驱动
Class.forName(“com.mysql.jdbc.Driver”);
//建立连接
Connection conn=DriverManager.getConnection(“jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8”,”root”,”123456”);
String Sql;
//增删改查的sql语句
Sql=”select * from subject”;
Sql=”insert into subject values(1003,’Dom’,1,3)”;
Sql=”update subject set subjectno=’1003’ where sno=’1002’”;
Sql=”delete from subject where subject=’1003’”;
//数据流工具
Statement st=conn.createStatement();
//ResultSet结果集是一个集合
ResultSet rs=st.executeQuery/Update(sql);
//遍历ResultSet
While(rs.next()){
Syso(rs.getInt(1)+” ”+rs.getString(“subjectname”));
}
//关闭流,后打开的先关闭
Rs.close();
St.close();
Conn.close();
![在这里插入图片描述](https://img-blog.csdnimg.cn/20190612192330873.jpg?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0FtZW5fV3U=,size_16,color_FFFFFF,t_70)