만사가귀찮다
38
2021-02-18 18:14:08 작성 2021-02-18 19:10:03 수정됨
0
226

crud 하는 중인데 한번만 봐주십셩 형님들 ㅠㅠ 다시 보기 좋게 수정했어요 봐주세용 !



package projectDAO;



import java.sql.Connection;

import java.sql.PreparedStatement;

import java.sql.ResultSet;

import java.sql.SQLException;



import projectVO.ProjectBoardVO;



public class ProjectBoardDAO {
	

	StringBuffer sb = null;

	Connection conn = null;

	PreparedStatement pstmt = null;

	ResultSet rs = null;

	

	// 싱글톤 패턴 

	public ProjectBoardDAO() {
		

		connection.OracleEXConnection.getInstance().getConnection();

	}

	

	public void InputData(ProjectBoardVO vo) {
		sb.setLength(0);

		sb.append("insert into project_board ");				//hits //sysdate //likes

		sb.append("values (project_board_seq.nextval, ?, ?, ?, 0, sysdate, 0, ?, ?, ?, ?, ? ) " );

		

		try {
			pstmt = conn.prepareStatement(sb.toString());

			

			pstmt.setNString(1, vo.getUser_id());

			pstmt.setNString(2, vo.getTitle());

			pstmt.setNString(3, vo.getContents());

			pstmt.setNString(4, vo.getWriter());

			pstmt.setNString(5, vo.getBoard_delete());

			pstmt.setNString(6, vo.getBoard_type());

			pstmt.setNString(7, vo.getLatitude());

			pstmt.setNString(8, vo.getLongitude());

			

			// 1개 부족하네요

			// 네 알겠습니다 찾아 고칠게요 감샇빈다 !

			pstmt.executeUpdate();

			

			

		} catch (SQLException e) {
			// TODO Auto-generated catch block

			e.printStackTrace();

		}

	}

}



---------------------------------------------------------------------- ↑ dao -------------------------------------------------

package projectVO;

public class ProjectBoardVO {
	int post_no;
	String user_id;
	String title;
	String contents;
	int hits;
	String write_date;
	int likes;
	String writer;
	String board_delete;
	String board_type;
	String latitude;
	String longitude;
	
	
	public ProjectBoardVO() {}


	public ProjectBoardVO(int post_no, String user_id, String title, String contents, int hits, String write_date,
			int likes, String writer, String board_delete, String board_type, String latitude, String longitude) {
		super();
		this.post_no = post_no;
		this.user_id = user_id;
		this.title = title;
		this.contents = contents;
		this.hits = hits;
		this.write_date = write_date;
		this.likes = likes;
		this.writer = writer;
		this.board_delete = board_delete;
		this.board_type = board_type;
		this.latitude = latitude;
		this.longitude = longitude;
	}


	public int getPost_no() {
		return post_no;
	}


	public void setPost_no(int post_no) {
		this.post_no = post_no;
	}


	public String getUser_id() {
		return user_id;
	}


	public void setUser_id(String user_id) {
		this.user_id = user_id;
	}


	public String getTitle() {
		return title;
	}


	public void setTitle(String title) {
		this.title = title;
	}


	public String getContents() {
		return contents;
	}


	public void setContents(String contents) {
		this.contents = contents;
	}


	public int getHits() {
		return hits;
	}


	public void setHits(int hits) {
		this.hits = hits;
	}


	public String getWrite_date() {
		return write_date;
	}


	public void setWrite_date(String write_date) {
		this.write_date = write_date;
	}


	public int getLikes() {
		return likes;
	}


	public void setLikes(int likes) {
		this.likes = likes;
	}


	public String getWriter() {
		return writer;
	}


	public void setWriter(String writer) {
		this.writer = writer;
	}


	public String getBoard_delete() {
		return board_delete;
	}


	public void setBoard_delete(String board_delete) {
		this.board_delete = board_delete;
	}


	public String getBoard_type() {
		return board_type;
	}


	public void setBoard_type(String board_type) {
		this.board_type = board_type;
	}


	public String getLatitude() {
		return latitude;
	}


	public void setLatitude(String latitude) {
		this.latitude = latitude;
	}


	public String getLongitude() {
		return longitude;
	}


	public void setLongitude(String longitude) {
		this.longitude = longitude;
	}

	

	
}



import java.sql.ResultSet;

import java.sql.SQLException;



import projectVO.ProjectBoardVO;



public class ProjectBoardDAO {
	

	StringBuffer sb = null;

	Connection conn = null;

	PreparedStatement pstmt = null;

	ResultSet rs = null;

	

	// 싱글톤 패턴 

	public ProjectBoardDAO() {
		

		connection.OracleEXConnection.getInstance().getConnection();

	}

	

	public void InputData(ProjectBoardVO vo) {
		sb.setLength(0);

		sb.append("insert into project_board ");				//hits //sysdate //likes

		sb.append("values (project_board_seq.nextval, ?, ?, ?, 0, sysdate, 0, ?, ?, ?, ?, ? ) " );

		

		try {
			pstmt = conn.prepareStatement(sb.toString());

			

			pstmt.setNString(1, vo.getUser_id());

			pstmt.setNString(2, vo.getTitle());

			pstmt.setNString(3, vo.getContents());

			pstmt.setNString(4, vo.getWriter());

			pstmt.setNString(5, vo.getBoard_delete());

			pstmt.setNString(6, vo.getBoard_type());

			pstmt.setNString(7, vo.getLatitude());

			pstmt.setNString(8, vo.getLongitude());

			

			// 1개 부족하네요

			// 네 알겠습니다 찾아 고칠게요 감샇빈다 !

			pstmt.executeUpdate();

			

			

		} catch (SQLException e) {
			// TODO Auto-generated catch block

			e.printStackTrace();

		}

	}

}




---------------------------------------------------------------------- ↑ dao -------------------------------------------------


package projectVO;

public class ProjectBoardVO {
	int post_no;
	String user_id;
	String title;
	String contents;
	int hits;
	String write_date;
	int likes;
	String writer;
	String board_delete;
	String board_type;
	String latitude;
	String longitude;
	
	
	public ProjectBoardVO() {}


	public ProjectBoardVO(int post_no, String user_id, String title, String contents, int hits, String write_date,
			int likes, String writer, String board_delete, String board_type, String latitude, String longitude) {
		super();
		this.post_no = post_no;
		this.user_id = user_id;
		this.title = title;
		this.contents = contents;
		this.hits = hits;
		this.write_date = write_date;
		this.likes = likes;
		this.writer = writer;
		this.board_delete = board_delete;
		this.board_type = board_type;
		this.latitude = latitude;
		this.longitude = longitude;
	}


	public int getPost_no() {
		return post_no;
	}


	public void setPost_no(int post_no) {
		this.post_no = post_no;
	}


	public String getUser_id() {
		return user_id;
	}


	public void setUser_id(String user_id) {
		this.user_id = user_id;
	}


	public String getTitle() {
		return title;
	}


	public void setTitle(String title) {
		this.title = title;
	}


	public String getContents() {
		return contents;
	}


	public void setContents(String contents) {
		this.contents = contents;
	}


	public int getHits() {
		return hits;
	}


	public void setHits(int hits) {
		this.hits = hits;
	}


	public String getWrite_date() {
		return write_date;
	}


	public void setWrite_date(String write_date) {
		this.write_date = write_date;
	}


	public int getLikes() {
		return likes;
	}


	public void setLikes(int likes) {
		this.likes = likes;
	}


	public String getWriter() {
		return writer;
	}


	public void setWriter(String writer) {
		this.writer = writer;
	}


	public String getBoard_delete() {
		return board_delete;
	}


	public void setBoard_delete(String board_delete) {
		this.board_delete = board_delete;
	}


	public String getBoard_type() {
		return board_type;
	}


	public void setBoard_type(String board_type) {
		this.board_type = board_type;
	}


	public String getLatitude() {
		return latitude;
	}


	public void setLatitude(String latitude) {
		this.latitude = latitude;
	}


	public String getLongitude() {
		return longitude;
	}


	public void setLongitude(String longitude) {
		this.longitude = longitude;
	}

	

	
}

------------------------------------------------------------------- ↑ vo -----------------------------------------------


package projectMain;

import projectDAO.ProjectBoardDAO;
import projectVO.ProjectBoardVO;

public class ProjectMain {
	public static void main(String[] args) {
		ProjectBoardDAO dao = new ProjectBoardDAO();
		
		ProjectBoardVO vo = new ProjectBoardVO();

		
		vo.setUser_id("호선");
		vo.setTitle("공부하자");
		vo.setContents("ㅇ ㅏ멍청해");
		vo.setWriter("sea3910");
		vo.setBoard_delete("삭제");
		vo.setBoard_type("");
		vo.setLatitude("35x");
		vo.setLongitude("56y");
		
		dao.InputData(vo);

	}
}

------------------------------------------------------------- ↑ 메인 -------------------------------------------------------
  CREATE TABLE "SCOTT"."PROJECT_BOARD" 
   (	"POST_NO" NUMBER NOT NULL ENABLE, 
	"USER_ID" VARCHAR2(20 BYTE) NOT NULL ENABLE, 
	"TITLE" VARCHAR2(20 BYTE), 
	"CONTENTS" VARCHAR2(250 BYTE), 
	"HITS" NUMBER NOT NULL ENABLE, 
	"WRITE_DATE" DATE NOT NULL ENABLE, 
	"LIKES" NUMBER, 
	"WRITER" VARCHAR2(20 BYTE), 
	"BOARD_DELETE" VARCHAR2(10 BYTE), 
	"BOARD_TYPE" CHAR(1 BYTE) NOT NULL ENABLE, 
	"LATITUDE" VARCHAR2(20 BYTE), 
	"LONGITUDE" VARCHAR2(20 BYTE), 
	 CONSTRAINT "BOARD_PK" PRIMARY KEY ("POST_NO") 여긴 오라클이요 !



--------------------------------------------------- 테이블 -------------------------------------------------

이렇게 했는데요 .. 다오에서 데이터 넣는 메소드 만들고 메인에서 

저렇게 데이터 집어 넣으려니까 눌포인트가 터지는데 당췌가 어디를 틀린지 모르겠어요 ...ㅜㅜ

한번만 봐주시고 지적주시면 감사하겠습니다 . ㅜㅜ

conn : oracle.jdbc.driver.T4CConnection@504bae78
Exception in thread "main" java.lang.NullPointerException
at projectDAO.ProjectBoardDAO.InputData(ProjectBoardDAO.java:29)
at projectMain.ProjectMain.main(ProjectMain.java:22)

오류는 이런 오류 뜨구요 ! 



0
  • 답변 0

  • 로그인을 하시면 답변을 등록할 수 있습니다.