第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

大神看看怎么有空指針錯(cuò)誤!感謝!

@GoddessAction.java

package com.imooc.action;


import java.util.Date;

import java.util.List;


import com.imooc.dao.GoddessDao;

import com.imooc.model.Goddess;


public class GoddessAction {

public static void main(String[] args) throws Exception

{

GoddessDao g=new GoddessDao();

List <Goddess> gs = g.query();

for(Goddess goddess:gs)

{

System.out.println(goddess.getUser_name()+","+goddess.getAge());

}

Goddess g1=new Goddess();

g1.setUser_name("娜美");

g1.setSex(1);

g1.setAge(100);

g1.setBirthday(new Date());

g1.setEmail("123456789@qq.com");

g1.setMobile("166645644");

g1.setUpdate_user("admin");

g1.setIsdel(1);

Goddess g2=g.get(5);

System.out.println(g2.toString());

//Goddess g2 = g.get(5);

//System.out.println(g2.toString());

//g1.setId(3);

//g.delGoddess(3);

//g.addGoddess(g1);

//g.updateGoddess(g1);

}

}

@GoddessDao

package com.imooc.dao;


import com.imooc.db.DBUtil;

import com.imooc.model.*;


import java.sql.Connection;


import java.sql.Date;

import java.sql.PreparedStatement;

import java.sql.ResultSet;

import java.sql.SQLException;

import java.sql.Statement;

import java.util.ArrayList;

import java.util.List;


//用于執(zhí)行業(yè)務(wù)方法

public class GoddessDao {


public void addGoddess(Goddess g) throws Exception {

Connection conn = DBUtil.getConnection();

String sql = "" + "insert into imooc_goddess"

+ "(user_name,sex,age,brithday,email,mobile,"

+ "create_user,create_date,update_user,update_date,isdel)"

+ "values("

+ "?,?,?,?,?,?,?,current_date(),?,current_date(),?)";

PreparedStatement ptmt = conn.prepareStatement(sql);

ptmt.setString(1, g.getUser_name());

ptmt.setInt(2, g.getSex());

ptmt.setInt(3, g.getAge());

ptmt.setDate(4, new Date(g.getBirthday().getTime()));

ptmt.setString(5, g.getEmail());

ptmt.setString(6, g.getMobile());

ptmt.setString(7, g.getCreate_user());

ptmt.setString(8, g.getUpdate_user());

ptmt.setInt(9, g.getIsdel());


ptmt.execute();

}


public void updateGoddess(Goddess g) throws SQLException {

Connection conn = DBUtil.getConnection();

String sql = "" + " update imooc_goddess"

+ " set user_name=?,sex=?,age=?,brithday=?,email=?,mobile=?,"

+ "update_user=?,update_date=current_date(),isdel=?"

+ " where id=?";

PreparedStatement ptmt = conn.prepareStatement(sql);

ptmt.setString(1, g.getUser_name());

ptmt.setInt(2, g.getSex());

ptmt.setInt(3, g.getAge());

ptmt.setDate(4, new Date(g.getBirthday().getTime()));

ptmt.setString(5, g.getEmail());

ptmt.setString(6, g.getMobile());

ptmt.setString(7, g.getUpdate_user());

ptmt.setInt(8, g.getIsdel());

ptmt.setInt(9, g.getId());


ptmt.execute();

}


public void delGoddess(Integer id) throws SQLException {

Connection conn = DBUtil.getConnection();

String sql = "" +?

" delete from imooc_goddess"+

" where id=?";

PreparedStatement ptmt = conn.prepareStatement(sql);

ptmt.setInt(1, id);


ptmt.execute();


}


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);

}

return gs;

}


public Goddess get(Integer id) throws SQLException {

Goddess g=null;

Connection conn = DBUtil.getConnection();

String sql = "" + " select * from imooc_goddess"

+ " where id=?";

PreparedStatement ptmt = conn.prepareStatement(sql);

ptmt.setInt(1, id);


ResultSet rs = ptmt.getResultSet();

while(rs.next())

{

g=new Goddess();

g.setUser_name(rs.getString("user_name"));

g.setSex(rs.getInt("sex"));

g.setAge(rs.getInt("age"));

g.setId(rs.getInt("id"));

g.setBirthday(rs.getDate("brithday"));

g.setEmail(rs.getNString("email"));

g.setMobile(rs.getString("mobile"));

g.setCreate_user(rs.getString("create_user"));

g.setUpdate_user(rs.getNString("create_user"));

g.setCreate_date(rs.getDate("create_date"));

g.setUpdate_date(rs.getDate("update_date"));

g.setIsdel(rs.getInt("isdel"));

}

return g;

}


}


Exception in thread "main" java.lang.NullPointerException

at com.imooc.dao.GoddessDao.get(GoddessDao.java:100)

at com.imooc.action.GoddessAction.main(GoddessAction.java:28)


正在回答

2 回答

get()方法少了?ResultSet rs = ps.executeQuery();

0 回復(fù) 有任何疑惑可以回復(fù)我~
#1

慕仰4084179 提問者

非常感謝!
2016-09-17 回復(fù) 有任何疑惑可以回復(fù)我~

看不出來,自己debug調(diào)試吧

0 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消

大神看看怎么有空指針錯(cuò)誤!感謝!

我要回答 關(guān)注問題
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)