package wang.wu.jsp;
import netscape.javascript.JSObject;
import org.json.JSONArray;
import org.json.JSONObject;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class SqlStatement {
SqlConnect connect=new SqlConnect();
String sql_data;
public boolean Add(Student student){
sql_data = "insert into user_data(username,sex,age,birthday,QQdata,telephone,constellation,nativeplace,dream,address,hobby,message) " +
"values('"+student.toString()+"')";
return localUpdata();
}
public boolean Delet(String id){
sql_data = "delete from user_data where id ='"+ id +"'";
return localUpdata();
}
public boolean Update(Student student){
sql_data = "update into user_data(username,sex,age,birthday,QQdata,telephone,constellation,nativeplace,dream,address,hobby,message) " +
"values('"+ student.toString()+"')";
return localUpdata();
}
public JSONArray backout(){
String sql = "select * from user_data";
JSONArray jArray=new JSONArray();
backout1(sql,jArray);
return jArray;
}
public void backout1(String sql,JSONArray jArray){
ResultSet resultSet = null;
try {
resultSet = connect.getStmt().executeQuery(sql);
}catch (SQLException e) {
e.printStackTrace();
}
try {
while(resultSet.next()) { //ResultSet 对象具有指向其当前数据行的光标。
//List使用
// List<String> dataArray = new ArrayList<>();
// int id=resultSet.getInt("id"); //id标识
// dataArray.add(String.valueOf(id));
// dataArray.add(resultSet.getString("username")); //名字
// dataArray.add(resultSet.getString("sex")); //性别
// dataArray.add(resultSet.getString("birthday"));
// dataArray.add(resultSet.getString("telephone")); //电话
//Map使用
Map<String,String> dataArray=new HashMap<>();
int id=resultSet.getInt("id"); //id标识
dataArray.put("id",String.valueOf(id));
dataArray.put("username",resultSet.getString("username")); //名字
dataArray.put("sex",resultSet.getString("sex")); //性别
dataArray.put("birthday",resultSet.getString("birthday")); //生日
dataArray.put("telephone",resultSet.getString("telephone")); //电话
jArray.put(dataArray);
}
resultSet.close();
}catch (SQLException e) {
e.printStackTrace();
}
}
public JSONArray lookup(String data){
if (data==null)
return null;
else{
String sql = "select * from user_data where username like '%"+data+"%' or sex like '%"+data+"%' or age like '%"+data+"%'";
JSONArray jArray=new JSONArray();
backout1(sql,jArray);
return jArray;
}
}
public JSONObject backout1(int ID){
String sql = "select * from user_data";
ResultSet result = null;
JSONObject jsonObject=new JSONObject();
try {
result = connect.getStmt().executeQuery(sql);
}catch (SQLException e) {
e.printStackTrace();
}
try {
while(result.next()) { //ResultSet 对象具有指向其当前数据行的光标。
if (ID==result.getInt("id")) {
jsonObject.put("username",result.getString("username")); //名字
jsonObject.put("sex",result.getString("sex")); //性别
int age = result.getInt("age"); //年龄
jsonObject.put("age",String.valueOf(age));
jsonObject.put("birthday",result.getString("birthday")); //生日
jsonObject.put("QQdata",result.getString("QQdata")); //QQ号
jsonObject.put("telephone",result.getString("telephone")); //电话
jsonObject.put("constellation",result.getString("constellation")); //星座
jsonObject.put("nativeplace",result.getString("nativeplace")); //籍贯
jsonObject.put("dream",result.getString("dream")); //梦想
jsonObject.put("address",result.getString("address")); //地址
jsonObject.put("hobby",result.getString("hobby")); //描述
jsonObject.put("message",result.getString("message")); //描述
return jsonObject;
}
}
result.close();
}catch (SQLException e) {
e.printStackTrace();
}
return null;
}
public boolean localUpdata(){
int acff=0;
try {
System.out.println(sql_data);
acff=connect.stmt.executeUpdate(sql_data);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(acff>0)
return true;
else
return false;
}
protected void finalize(){
connect.disconnect();
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
Web 开发(jsp) 同学录(增删该查) (112个子文件)
SqlStatement.class 5KB
SqlStatement.class 5KB
Student.class 4KB
Student.class 4KB
SqlConnect.class 2KB
SqlConnect.class 2KB
Studentdata.class 1KB
Studentdata.class 1KB
mainpage.class 1KB
mainpage.class 1KB
inputdata.class 866B
inputdata.class 866B
bootstrap.css 143KB
bootstrap.css 143KB
bootstrap.min.css 118KB
bootstrap.min.css 118KB
bootstrap-theme.css 26KB
bootstrap-theme.css 26KB
bootstrap-theme.min.css 23KB
bootstrap-theme.min.css 23KB
Untitled-2.css 938B
Untitled-2.css 938B
Untitled-2.css 483B
Untitled-2.css 483B
index.css 454B
index.css 454B
glyphicons-halflings-regular.eot 20KB
glyphicons-halflings-regular.eot 20KB
Web_examination_assignments.iml 2KB
sqljdbc4-2.0.jar 455KB
sqljdbc4-2.0.jar 455KB
standard.jar 384KB
standard.jar 384KB
json-20180130.jar 61KB
json-20180130.jar 61KB
jstl.jar 20KB
jstl.jar 20KB
SqlStatement.java 6KB
Student.java 3KB
Studentdata.java 3KB
SqlConnect.java 1KB
mainpage.java 918B
inputdata.java 652B
wangwujie.jpg 1001KB
wangwujie.jpg 1001KB
de5227df6b838ea20f7e4f9c4058845d.jpg 547KB
de5227df6b838ea20f7e4f9c4058845d.jpg 547KB
1518925818_MjJLQAjd.jpg 156KB
1518925818_MjJLQAjd.jpg 156KB
images2.jpg 8KB
images2.jpg 8KB
images5.jpg 4KB
images5.jpg 4KB
images.jpg 3KB
images.jpg 3KB
jquery-3.3.1.js 265KB
jquery-3.3.1.js 265KB
jquery-3.3.1.min.js 85KB
jquery-3.3.1.min.js 85KB
bootstrap.js 68KB
bootstrap.js 68KB
bootstrap.min.js 36KB
bootstrap.min.js 36KB
npm.js 484B
npm.js 484B
update_data.jsp 6KB
update_data.jsp 6KB
input_data.jsp 5KB
input_data.jsp 5KB
index.jsp 4KB
index.jsp 4KB
alumni_book.jsp 4KB
alumni_book.jsp 4KB
lookup.jsp 3KB
lookup.jsp 3KB
check_data.jsp 2KB
check_data.jsp 2KB
ceshi.jsp 1KB
ceshi.jsp 1KB
user.jsp 1KB
user.jsp 1KB
input_check.jsp 996B
input_check.jsp 996B
delete.jsp 644B
delete.jsp 644B
Web_examination_assignments.kotlin_module 16B
Web_examination_assignments.kotlin_module 16B
bootstrap.min.css.map 529KB
bootstrap.min.css.map 529KB
bootstrap.css.map 380KB
bootstrap.css.map 380KB
bootstrap-theme.css.map 47KB
bootstrap-theme.css.map 47KB
bootstrap-theme.min.css.map 25KB
bootstrap-theme.min.css.map 25KB
glyphicons-halflings-regular.svg 106KB
glyphicons-halflings-regular.svg 106KB
glyphicons-halflings-regular.ttf 44KB
glyphicons-halflings-regular.ttf 44KB
glyphicons-halflings-regular.woff 23KB
共 112 条
- 1
- 2
资源评论
- weixin_436442152020-06-06代码运行不了仰望星空0072020-10-27有买后保障服务仰望星空0072020-10-27代码重新给你,帮你运行好。仰望星空0072020-06-19能够运行
仰望星空007
- 粉丝: 309
- 资源: 12
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功