对表中数据的四大基本操作
1.增加数据:insert into 表名 (字段名(id)1,字段名(名字)2…)values(值1,值2,)
查询表中数据:select *from 表名;
第一步:
将连接数据库驱动包,复制放入web—INF/lib文件夹中
第二步:
新建类在类中定义三个属性
final static string DB_URL=“jdbc:mylqc://loclahost:3306//库名,”
final static string USER ="root";
final static string PASS ="密码";
第三步:
public Util(){
//加载驱动
Class.forName("com.mysql.jdbc.Driver");
//建立连接
Connection conn=DriverManager.getConnection(DB_URL,USER,PASS);
//执行sql语句
Statement stent=conn.createStatemnt();
String sql="select * from anzhouyiban";
ResultSet rs=stent.executeQuery(sql);
//获得结果
while(rs.next()){
int id=rs.getInt("id");
String name=rs.getString("name");
String name=rs.getString("xingbie");
}
//关闭连接
}