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

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定

JDBC空指針異常

找了半天也沒找到,究竟哪里出錯了。
package?dao;

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;

import?com.imooc.DBUtil;

import?model.Goddess;

public?class?GoddessDao?{
	public?void?addGoddess(Goddess?g)?throws?Exception{
		Connection?conn=DBUtil.getConnection();
		String?sql=""?+
				"insert?into?imooc_goddess"?+
				"(user_name,sex,age,birthday,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(){
		
	}
	public?void?delGoddess(){
		
	}
	public?List<Goddess>?query()?throws?SQLException{
		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(){
		return?null;
	}
}
package?model;

import?java.util.Date;

public?class?Goddess?{
	private?Integer?id;
	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;
	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?com.imooc.action;

import?java.util.Date;
import?java.util.List;

import?model.Goddess;
import?dao.GoddessDao;

public?class?GoddessAction?{
	public?static?void?main(String[]?args)?throws?Exception?{
		GoddessDao?g=new?GoddessDao();
		Goddess?gl=new?Goddess();
		gl.setUser_name("小夏");
		gl.setAge(22);
		gl.setSex(1);
		gl.setBirthday(new?Date());
		gl.setEmail("xiaoxia@imooc.com");
		gl.setCreate_user("ADMIN");
		gl.setUpdate_user("ADMIN");
		gl.setId(1);
		g.addGoddess(gl);
//		List<Goddess>?gs=g.query();
//		for(Goddess?goddess:gs){
//			System.out.println(goddess.getUser_name()+","+goddess.getAge());
//		}
	}
}
package?com.imooc;

import?java.sql.Connection;
import?java.sql.DriverManager;
import?java.sql.ResultSet;
import?java.sql.SQLException;
import?java.sql.Statement;

public?class?DBUtil?{
	private?static?final?String?URL="jdbc:mysql:///imooc";
	private?static?final?String?USER="root";
	private?static?final?String?PASSWORD="wo123wo";
	private?static?Connection?conn=null;
	static{
		try?{
			Class.forName("com.mysql.jdbc.Driver");
			Connection?conn=DriverManager.getConnection(URL,?USER,?PASSWORD);
		}?catch?(ClassNotFoundException?e)?{
			//?TODO?Auto-generated?catch?block
			e.printStackTrace();
		}?catch?(SQLException?e)?{
			//?TODO?Auto-generated?catch?block
			e.printStackTrace();
		}
	}
	public?static?Connection?getConnection(){
		return?conn;
	}
	public?static?void?main(String[]?args)?throws?Exception?{
		Class.forName("com.mysql.jdbc.Driver");
		Connection?conn=DriverManager.getConnection(URL,?USER,?PASSWORD);
		Statement?stmt=conn.createStatement();
		ResultSet?rs=stmt.executeQuery("select?user_name,age?from?imooc_goddess");
		while(rs.next()){
			System.out.print(rs.getString("user_name")+","+rs.getInt("age"));
		}
	}
}


正在回答

3 回答

在action里加? update_date并賦值? ?你的新建Date沒有賦值所以顯示空指針異常


0 回復(fù) 有任何疑惑可以回復(fù)我~
Date?date1=new?Date();
		SimpleDateFormat?sdf?=?new?SimpleDateFormat("yyyy-MM-dd?HH:mm:ss");
		date1?=?sdf.parse("2008-08-08?12:10:12");
g1.setCreate_date(date1);


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

DBUtil類中第17行“Connection?conn=DriverManager.getConnection(URL,?USER,?PASSWORD);”,去掉“Connection”,直接給你之前定義的靜態(tài)變量conn賦值

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

舉報

0/150
提交
取消
JDBC之 “ 對岸的女孩看過來”
  • 參與學(xué)習(xí)       99327    人
  • 解答問題       915    個

一起領(lǐng)略JDBC的奧秘,為進(jìn)一步學(xué)習(xí)集成框架打下良好的基礎(chǔ)

進(jìn)入課程

JDBC空指針異常

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

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

幫助反饋 APP下載

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

公眾號

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