help 청함니다....
Hotpants
과제로 bd연동을 해서 명함관리 프로그램을 만드는 겁니다....
NullpointException이 나와서 지금 진도를 못 나가고 있습니다..
초보라 에러 이유는 알겠는데... 해결방법을 모르겠습니다..
import java.io.*;
import java.sql.*;
public class Exchange_Card {
public static void main(String[] ar)throws IOException {
BufferedReader in = new BufferedReader(
new InputStreamReader(System.in));
Exchange e = new Exchange();
InsertMember im = new InsertMember();
UpdateMember um = new UpdateMember();
DeleteMember dm = new DeleteMember();
String str;
while(true){
System.out.println(################################################);
System.out.println( 명 함 초 기 화 면 );
System.out.println(################################################);
System.out.println();
System.out.print(이름 : );
String name = in.readLine();
System.out.print(전화 번호 : );
String tel = in.readLine();
System.out.print(이메일 : );
String email = in.readLine();
System.out.print(팩스 : );
String fax = in.readLine();
System.out.print(홈페이지 : );
String homepage = in.readLine();
System.out.print(회사명 : );
String company = in.readLine();
System.out.print(직책 : );
String position = in.readLine();
System.out.print(주소 : );
String add = in.readLine();
boolean bool = e.loginMember(name,tel,email,fax,homepage,company,position,add); ---NullPointException발생
if(bool){
System.out.println(이름 : + name);
System.out.println(전화번호 + tel);
System.out.println(이메일 + email);
System.out.println(팩스 + fax);
System.out.println(홈페이지 + homepage);
System.out.println(회사명 + company);
System.out.println(직책 + position);
System.out.println(주소 + add);
System.out.print(명함관리 [P(revious), N(ext), I(nsert), U(pdate), D(elete)]?);
str = in.readLine();
}
else{
System.out.println([현재, 입력된 내용이 없습니다!]);
System.out.print(명함관리 [P(revious), N(ext), I(nsert), U(pdate), D(elete)]?);
str = in.readLine();
}
if(str.equals(I) || str.equals(i)){
im.display();
if(str.equals(P) || str.equals(p)){ continue;}
else if(str.equals(N) || str.equals(n)){ um.display();}
}
else if(str.equals(U)|| str.equals(u)){
um.display();
if(str.equals(P) || str.equals(p)){ continue;}
else if(str.equals(N) || str.equals(n)){ dm.display();}
}
else if(str.equals(D) || str.equals(d)){
dm.display();
if(str.equals(P) || str.equals(p)){ continue;}
else if(str.equals(N) || str.equals(n)){
System.out.println(더이상 페이지가 없습니다.);}
}
else{
System.out.println(잘못 입력하셨습니다.);
}
}
} //method
} //classimport java.sql.*;
public class Exchange {
private Connection dc;
public Exchange(){
try{
Class.forName(oracle.jdbc.driver.OracleDriver);
}
catch(ClassNotFoundException ee){return;}
Connection conn = null;
String url = jdbc:oracle:thin:@192.168.1.3:9625:ora92;
String id = scott;
String pass = tiger;
try{
conn = DriverManager.getConnection(url,id,pass);
}
catch(SQLException ee){ }
}
//데이터가 있는지 확인위해..(로그인)
public boolean loginMember(String name, String tel, String email, String fax,
String homepage, String company, String position, String add){
String query =
select * form exchange_card where name = ? or tel = ? or email = ? or fax = ? or homepage = ? or conpany = ? or position = ? or addr = ? ;
try{
PreparedStatement pstmt = dc.prepareStatement(query); ---NullPointException발생
pstmt.setString(1,name);
pstmt.setString(2,tel);
pstmt.setString(3,email);
pstmt.setString(4,fax);
pstmt.setString(5,homepage);
pstmt.setString(6,company);
pstmt.setString(7,position);
pstmt.setString(8,add);
ResultSet rs = pstmt.executeQuery();
if(!rs.next()){
rs.close();
&nbsbsp;pstmt.close();
return false;
}
rs.close();
pstmt.close();
}catch(SQLException ee){}
return true;
}
//삭제를 위해
public boolean deleteMember(String name, String email){
String query =
delete form exchange_card where name =?, email = ?;;
try{
PreparedStatement pstmt = dc.prepareStatement(query);---NullPointException발생
pstmt.setString(1, name);
pstmt.setString(2, email);
pstmt.executeUpdate();
pstmt.close();
}catch(SQLException ee){
return false;
}
return true;
}
//입력을 위해서...
public boolean insertMember(String name,String tel,
String email,String fax,String homepage,String conpany,
String position,String addpost,String add ){
String query =
insert into exchange_card value(s_seq.NEXTVAL,?,?,?,?,?,?,?,?,?;
try{
PreparedStatement pstmt = dc.prepareStatement(query);---NullPointException발생
pstmt.setString(1,name);
pstmt.setString(2,tel);
pstmt.setString(3,email);
pstmt.setString(4,fax);
pstmt.setString(5,homepage);
pstmt.setString(6,conpany);
pstmt.setString(7,position);
pstmt.setString(8,addpost);
pstmt.setString(9,add);
pstmt.executeUpdate();
pstmt.close();
}catch(SQLException se){
System.out.println(데이터 입력 실패);
return false;
}
return true;
}
//수정을 위해서...
public boolean updateMember(String newname, String newtel,
String newemail,String newfax, String newhomepage, String newconpany,
String newposition, String newaddpost,String newadd, String name, String email){
String query =
update exchange_card set name = ?,tel = ?,email = ? +
fax = ?,homepage = ?,conpany = ?,position = ?,addpost = ? +
,addr =? where name =? and email = ?;
try{
PreparedStatement pstmt = dc.prepareStatement(query);---NullPointException발생
pstmt.setString(1,newname);
pstmt.setString(2,newtel);
pstmt.setString(3,newemail);
pstmt.setString(4,newfax);
pstmt.setString(5,newhomepage);
pstmt.setString(6,newconpany);
pstmt.setString(7,newposition);
pstmt.setString(8,newaddpost);
pstmt.setString(9,newadd);
pstmt.setString(10,name);
pstmt.setString(11,email);
pstmt.executeQuery();
pstmt.close();
}catch(SQLException ee){
System.err.println(정보 수정 실패);
return false;
}
return true;
}
}
===============insert ===================
import java.io.*;
import java.sql.*;
class InsertMember{
public void display() throws IOException{
BufferedReader in = new BufferedReader(
new InputStreamReader(System.in));
Exchange e = new Exchange();
System.out.print(이름은(*) [최대10자]?);
String name = in.readLine();
System.out.print(전화번호는(*) [최대20자]?);
String tel = in.readLine();
System.out.print(이메일은(*) [최대30자]?);
String email = in.readLine();
System.out.print(팩스는 [최대20자]?);
String fax = in.readLine();
System.out.print(홈페이지 [최대0자]?);
String homepage = in.readLine();
System.out.print(회사명은 [최대20자]?);
String conpany = in.readLine();
System.out.print(직책은 [최대10자]?);
String position = in.readLine();
System.out.print(우편번호 [최대7자]?);
String addpost = in.readLine();
System.out.print(주소 [최대50자]?);
String add = in.readLine();
System.out.print(위의 내용을 입력하시겠습니까?(y/n) );
String str = in.readLine();
if(str.equals(Y) || str.equals(y)){
boolean bool = e.insertMember(name,add,email,fax,
homepage,conpany,position,addpost,add);---NullPointException발생
System.out.println(데이터를 입력 합니다.);
if(bool){
System.out.println(데이터가 입력 되었습니다.);
}else{
System.out.println(데이터가 입력 되지않았습니다.);
}
return;
}
else if(str.equals(N) || str.equals(n)){
System.out.println(데이터가 입력 하지않았습니다.);
return;
}
}//method
}//class
===============update ===================
import java.io.*;
import java.sql.*;
class UpdateMember{
public void display() throws IOException{
BufferedReader in = new BufferedReader(
new InputStreamReader(System.in));
Exchange e = new Exchange();
System.out.print(이름 : );
String name = in.readLine();
System.out.print(새값 : );
String newname = in.readLine();
System.out.println();
System.out.print(전화전호 : );
String tel = in.readLine();
System.out.print(새값 : );
String newtel = in.readLine();
System.out.println();
System.out.print(이메일 : );
String email = in.readLine();
System.out.print(새값 : );
String newemail = in.readLine();
System.out.println();
System.out.print(팩스 : );
String fax = in.readLine();
System.out.print(새값 : );
String newfax = in.readLine();
System.out.println();
System.out.print(홈페이지 : );
String homepage = in.readLine();
System.out.print(새값 : );
String newhomepage = in.readLine();
System.out.println();
System.out.print(회사명 : );
String company = in.readLine();
System.out.print(새값 : );
String newcompany = in.readLine();
System.out.println();
System.out.print(직책 : );
String position = in.readLine();
System.out.print(새값 : );
String newposition = in.readLine();
System.out.println();
System.out.print(우편번호 : );
String addpost = in.readLine();
System.out.print(새값 : );
String newaddpost = in.readLine();
System.out.println();
System.out.print(주소 : );
String add = in.readLine();
System.out.print(새값 : );
String newadd = in.readLine();
System.out.println();
Systesp;System.out.print(위의 내용으로 수정 하시겠습니까?(y/n));
String str = in.readLine();
if(str.equals(Y) || str.equals(y)){
boolean bool = e.updateMember(newname,newtel,newemail,newfax,
newhomepage,newcompany,newposition,newaddpost,newadd,name,email);---NullPointException발생
System.out.println(데이터를 수정 합니다.);
if(bool){
System.out.println(데이터가 수정 되었습니다.);
}
else{
System.out.println(데이터가 수정되지 않았습니다.);
}
return;
}
else if(str.equals(N) || str.equals(n)){
System.out.println(데이터를 수정하지 않습니다.);
return;
}
}//method
}// class
=============== delete ===================
import java.io.*;
import java.sql.*;
class DeleteMember{
public void display()throws IOException{
BufferedReader in = new BufferedReader(
new InputStreamReader(System.in));
Exchange e = new Exchange();
String str;
System.out.print(정말 삭제를 하시겠습니까?(y/n));
str = in.readLine();
if(str.equals(Y) || str.equals(y)){
System.out.print(이름 :);
String name = in.readLine();
System.out.print(이메일 :);
String email = in.readLine();
boolean bool = e.deleteMember(name,email);---NullPointException발생
System.out.println(데이터를 삭제합니다.);
if(bool){
System.out.println(데이터가 삭제되었습니다.);
}else{
System.out.println(데이터가 삭제되지 않았습니다.);
}
return;
}
else if(str.equals(N) || str.equals(n)){
System.out.println(데이터를 삭제하지 않습니다.);
return;
}
}
}
-
상1큼해
dc 에 아무런 객체도 들어 있지 않아서 생기는 문제 입니다.;;
dc = ..... 이라고 되어 있는 코드가 한군데도 안 보이는데..
객체가 없으니. null일 수 밖에요~ -
빗줄기
NullPointException이 발생하는 위치를 표시 해 놓았습니다...
-
이송이
그렇죠 --
-
맑다
에러가 나면.. 에러 메세지를 보여 주어야.. 뭐가 잘못되었는지 더 잘 알려 드릴 수 있습니다.
-
Sona
그것도 안된다면..각 실행하는 부분에 system.out.println(\Test1\);
이런식으로 다 찍어서 어느 부분에서 걸리는지 확인하는 방법도 있습니다.
모든게 다 정상적인데 안되면..뭐..찍어봐야죠..
try catch가 다..찍어줄수 없을때만 쓰시면 됩니다. -
하예라
catch 문에서 에러를 찍지 않는 것은 개발이 끝난 후에.. 바꿔주시는 것이 좋구요..
개발할때에는 모든 에러를 출력해주시는 것이 좋답니다. -
김애교
차라리.. try {} catch 문을 수정해보세요...
try {...} catch (Exception e) { e.printStackTrace(); }
이렇게 해주시면 에러가 나는 부분을 정확하게는 아니지만 대부분 찍어준답니다. -
청식
ㅎㅎㅎ
어디선가 정말 null값이 들어왔겠죠..
insert into exchange_card value(s_seq.NEXTVAL,?,?,?,?,?,?,?,?,?\;
그리고 이 부분 ) 빠져 있습니다.
뭐.제가 실행할 시간은 없어서 대충 봤는데..저두 어디가 나는지는 실행 시켜봐야 알꺼 같네요..ㅎㅎ
그리고 가급적 들어오는 문자에 대해서는 비교할때
대문자로 통일시키던가 소문자로 통일시키세요~
조금이라두 글수 줄여야죠..
그리고 한곳에 몰아 넣든 나누던 -
달
NullPointException이 어디서 나는진 파악은 했습니다... 근데 분명 제 생각에는 에러 날 부분이 안닌것 같고.. 그래서 생각 한것이 클래스를 나눈것을 한 클래스안에 넣어 볼까하는데요... 좋은 생각일까요??ㅡㅡㅋ
-
푸르나
실행하였을때 NullpointException이..어디서 나는지 그것먼저 파악하세요...
어느 부분에서 null이 나는지 파악후에 왜 그런지 분석하면 되겠지요 ^^