First you will need sql language, if you can see this post less likely to sql (https://blog.csdn.net/baidu_38978508/article/details/88901870)
To give you a better understanding of the development of sql in javweb deletions change check, the following examples are based on the entire function performed.
1, by (insert)
Key! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !
sql language, that is, to the forthcoming implementation of the language.
String sql = "insert into room(name,email,phone,sex,money,price,type,time,content) values(?,?,?,?,?,?,?,?,?)";//sql语言
A wear parameter placeholder
stm = conn.prepareStatement(sql);//预处理的对象
stm.setString(1, name);//这里进行传参数,非常重要
stm.setString(2, email);
stm.setString(3, phone);
stm.setString(4, sex);
stm.setInt(5, money);
stm.setString(6, price);
stm.setString(7, type);
stm.setString(8, time);
stm.setString(9, content);
rs = stm.executeUpdate();//动态的执行insert updata delete的语句
The entire function
public void addRoom(String name,int money, String email, String phone, String type, String sex, String price, String time,
String content) {
// TODO Auto-generated method stub
Connection conn = DBUtil.getConnectDb();
String sql = "insert into room(name,email,phone,sex,money,price,type,time,content) values(?,?,?,?,?,?,?,?,?)";//sql语言
int rs = 0;
PreparedStatement stm = null;
try {
stm = conn.prepareStatement(sql);//预处理的对象
stm.setString(1, name);//这里进行传参数,非常重要
stm.setString(2, email);
stm.setString(3, phone);
stm.setString(4, sex);
stm.setInt(5, money);
stm.setString(6, price);
stm.setString(7, type);
stm.setString(8, time);
stm.setString(9, content);
rs = stm.executeUpdate();//动态的执行insert updata delete的语句
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
2, check (the SELECT)
(1) there is no query parameters
public ArrayList<RoomBean> getRoomList() {
// TODO Auto-generated method stub
ArrayList<RoomBean> tag_Array = new ArrayList<RoomBean>();
Connection conn = DBUtil.getConnectDb();
String sql = "select * from room";//从room表中拿到数据
PreparedStatement stm = null;
ResultSet rs = null;
try {
stm = conn.prepareStatement(sql);
rs = stm.executeQuery();
while(rs.next()){//通过游标提取数据,进行循环
RoomBean tag = new RoomBean();
tag.setId(rs.getInt("id"));
tag.setName(rs.getString("name"));
tag.setEmail(rs.getString("email"));
tag.setPhone(rs.getString("phone"));
tag.setSex(rs.getString("sex"));
tag.setMoney(rs.getInt("money"));
tag.setPrice(rs.getString("price"));
tag.setType(rs.getString("type"));
tag.setTime(rs.getString("time"));
tag.setContent(rs.getString("content"));
tag_Array.add(tag);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
DBUtil.CloseDB(rs, stm, conn);
}
return tag_Array;
}
(2) transfer parameter query
public int getRoom(int id) {
// TODO Auto-generated method stub
int money = 0;
Connection conn = DBUtil.getConnectDb();
String sql = "select * from room where id="+id;
PreparedStatement stm = null;
ResultSet rs = null;//相当于临时表
try {
stm = conn.prepareStatement(sql);//预处理对象
rs = stm.executeQuery();//获取结果集
//从当前游标开始到下一行next
if(rs.next()){
money = rs.getInt("money");
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
DBUtil.CloseDB(rs, stm, conn);
}
return money;
}
3, update (update)
public void updateRoom(int id, int price) {
// TODO Auto-generated method stub
Connection conn = DBUtil.getConnectDb();
String sql = "update room set money=? where id=?";//sql
PreparedStatement stm = null;
int money = this.getRoom(id);
money = money - price;
try {
stm = conn.prepareStatement(sql);
stm.setInt(1, money);//传参数同样很重要
stm.setInt(2, id);
stm.executeUpdate();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
4, delete (delete)
public void deleteRoom(int id) {
// TODO Auto-generated method stub
Connection conn = DBUtil.getConnectDb();
String sql = "delete from room where id=?";
PreparedStatement stm = null;
try {
stm = conn.prepareStatement(sql);
stm.setInt(1, id);
stm.executeUpdate();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Undertake graduation: micro-channel applets, ssm Raspberry Pi hardware and
have developed a good graduation can buy cheaper prices.
Scanning micro-channel two-dimensional code plus the following (You Are):