关闭

java 女神管理系统1

标签: javajdbc
87人阅读 评论(0) 收藏 举报
分类:

======================= http://www.imooc.com/video/5229/0


mysql代码:

CREATE TABLE `imooc_goddess` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `user_name` varchar(30) NOT NULL,
  `sex` int(11) DEFAULT NULL,
  `age` int(11) DEFAULT NULL,
  `birthday` date DEFAULT NULL,
  `email` varchar(30) DEFAULT NULL,
  `mobile` varchar(11) DEFAULT NULL,
  `create_user` varchar(30) DEFAULT NULL,
  `create_date` date DEFAULT NULL,
  `update_user` varchar(30) DEFAULT NULL,
  `update_date` date DEFAULT NULL,
  `isdel` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;

===============================================================================================================

package modol1;

import java.util.Date;
public class Goddess {
//使用util包下的日期类型
//第一步:对应数据库表:把表的字段变成一个实体类 ,封装起

private String user_name;
private Integer sex;
private Integer age;
private Date birthday;
private String email;
private String mobile;
private String create_user;
private String update_user;//
private Date create_date;//创建日期
private Date update_date;//更新日期
private Integer isdel;//是否删除的标记
private Integer id;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getUser_name() {
return user_name;
}
public void setUser_name(String user_name) {
this.user_name = user_name;
}
public Integer getSex() {
return sex;
}
public void setSex(Integer sex) {
this.sex = sex;
}
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
public Date getBirthday() {
return birthday;
}
public void setBirthday(Date birthday) {
this.birthday = birthday;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getMobile() {
return mobile;
}
public void setMobile(String mobile) {
this.mobile = mobile;
}
public String getCreate_user() {
return create_user;
}
public void setCreate_user(String create_user) {
this.create_user = create_user;
}
public String getUpdate_user() {
return update_user;
}
public void setUpdate_user(String update_user) {
this.update_user = update_user;
}
public Date getCreate_date() {
return create_date;
}
public void setCreate_date(Date create_date) {
this.create_date = create_date;
}
public Date getUpdate_date() {
return update_date;
}
public void setUpdate_date(Date update_date) {
this.update_date = update_date;
}
public Integer getIsdel() {
return isdel;
}
public void setIsdel(Integer isdel) {
this.isdel = isdel;
}

}

=========================================================================================================================

查询多个女神

package modoldao1;
import modol1.Goddess;
import modoljdbc1.DBUtil;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
public class GoddessDao {
    public void addGodess(){
   
    }
    public void updateGoddess(){
   
    }
public void delGoddess(){
   
    }
public List<Goddess> query() throws Exception{
   Connection conn= DBUtil.getConnection();
   Statement stmt=conn.createStatement();
ResultSet rs= stmt.executeQuery("select  user_name,age from   imooc_goddess");
List<Goddess> gs=new ArrayList<Goddess>();
Goddess g=null;
while(rs.next()){
g=new Goddess();
g.setUser_name(rs.getString("user_name"));
g.setAge(rs.getInt("age"));
gs.add(g);
// System.out.println(rs.getString("user_name")+","+rs.getInt("age"));
}
return gs;
}
    public  Goddess get(){
    return null;
   
    }
}

=====================================================================================================================

连接数据库代码

package modoljdbc1;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;


public class DBUtil {
 private static final String URL="jdbc:mysql://127.0.0.1:3306/imooc?useUnicode=true&amp;characterEncoding=utf-8";
private static final String USER="root";
private static final String PASSWORD="123456";
private static Connection conn=null;


  static {
 try {
Class.forName("com.mysql.jdbc.Driver");
conn= DriverManager.getConnection(URL, USER, PASSWORD);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
 
  }
  public static Connection getConnection(){
 return conn;
  }
  } 

=========================================================================================================================

测试代码

package modolaction;
import java.util.List;
import modol1.Goddess;
import modoldao1.GoddessDao;
public class Action {


/**
* @param args
* @throws Exception 
*/
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
GoddessDao a=new GoddessDao();
List<Goddess> gs=a.query();
for(Goddess goddess:gs){
System.out.println(goddess.getUser_name()+","+goddess.getAge());
}
}


}


1
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:12598次
    • 积分:926
    • 等级:
    • 排名:千里之外
    • 原创:67篇
    • 转载:26篇
    • 译文:13篇
    • 评论:0条
    最新评论