jdbc连接`
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class Test_Find {
/**
* 1.注册数据库种类
* 2.创建通道.
* 3.在通道上创建一个运输工具.
* 4.将sql(select * from table)命令传送到数据库中.
* 数据库根据查询命令,获得一个临时表.
* 数据库会通过运输工具,将临时表传回内存
* 5.遍历循环,将内存中临时表的数据读取.
* 6.手动销毁资源.
* @throws ClassNotFoundException
* @throws SQLException
*/
public static void main(String[] args) throws ClassNotFoundException, SQLException {
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/studeydb","root","123");
Statement car = con.createStatement();
String sql ="select * from stu";
ResultSet table= car.executeQuery(sql);
while(table.next()){
//当前行,每一个字段的内容
int sno=table.getInt("sno");
String sname=table.getString("sname");
String sex = table.getString("sex");
System.out.println(sno+" "+sname+" "+sex);
}
table.close();
car.close();
con.close();
}
}'