제 소스 좀 봐주세요..제발...


[ 다음 글들 ] [ 이어서 글올리기(답하기) ] [ 자바 묻고 답하기 ]

글쓴이 :김현철 2000년 6월 27일 16:07:38

DB에 update하는 문제인데요..
클래스 안에 같은 방법으로 DB에 update 하는 메소드가
2개(UpdateDB, UpdateRefDB)있는데 앞의것은 잘되는데
뒤에 것(UpdateRefDB)가 도대체 update되질 않습니다.
며칠째 고생하다 고수님들의 조언을 얻고자 합니다.
부탁드립니다.


//문제의 소스...


package Admin;


import java.io.*;
import java.text.*;
import java.util.*;
import java.io.IOException;
import java.sql.*;
import java.sql.SQLException;
import Admin.*;


public class DBupdate {
/* 한글 처리 부분
public static String GetKoreanToDB(String Source)
{
String KrStr = null;
byte byteData[];

try
{
byteData = Source.getBytes("KSC5601");
KrStr = new String(byteData, "8859_1");
}
catch(UnsupportedEncodingException e){}

return KrStr;
}
*/


public void UpdateDB(String wLastId)
{
Connection conn= null;
PreparedStatement ps =null;
//ResultSet rs =null;
String stmt = null;
String wFileName = null;
String fName = null;


// 1. jdbc driver 를 등록한다.
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch (ClassNotFoundException e )
{
System.err.println("Class Not Found : " + e.getMessage());
}


// 2. DB와 연결한다.
try
{
String url = "jdbc:odbc:eBack";
conn = DriverManager.getConnection(url,"sa","");
}
catch (SQLException e)
{
System.err.println("SQL Error : " + e.getMessage());
}


// 3. update
try
{
// 한글 변환
wFileName = "data" + wLastId;
// fName = new String(wFileName); //wFileName은 넘겨받은 FileName

ps = conn.prepareStatement( "update Banner set " + "FileName = ? Where ID= ? " );
ps.setString(1,wFileName);
ps.setString(2,wLastId);
ps.execute();

// 4.db를 닫는다.
ps.close();
conn.close();
System.out.println("자료 저장 완료");

}
catch (SQLException e)
{
System.out.println(e);
}
}


public void UpdateRefDB()
{
Connection conn= null;
PreparedStatement ps =null;
//ResultSet rs =null;
String stmt = null;


// 1. jdbc driver 를 등록한다.
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch (ClassNotFoundException e )
{
System.err.println("Class Not Found : " + e.getMessage());
}


// 2. DB와 연결한다.
try
{
String url = "jdbc:odbc:eBack";
conn = DriverManager.getConnection(url,"sa","");
}
catch (SQLException e)
{
System.err.println("SQL Error : " + e.getMessage());
}


// 3. Reference field Update
String szBannerNameTime = null;
String Fname = null;
String Ftime = null;
int count = 0;

AllDBread rDB;
rDB = new AllDBread();
ResultSet rsUse = null;
ResultSet rsUseCount = null;

rsUse = rDB.ReadDB("SELECT DispTime, FileName FROM Banner Where UseStatus = 1");
rsUseCount = rDB.ReadDB("SELECT count(*) as Value FROM Banner Where UseStatus = 1");

//Recordset Count값얻기.
try
{
if(!rsUseCount.wasNull())
{
rsUseCount.next();
count = rsUseCount.getInt("Value");
}
if(!rsUse.wasNull() && count > 0)
{
String[] pBannerName = new String[count];
String[] szBannerName = new String[count];
String[] pBannerTime = new String[count];
String[] szBannerTime = new String[count];
rsUse.next();
for(int i=0; i<count;i++)
{
pBannerName[i] = pBannerName[i] + rsUse.getString("FileName") ;
szBannerName[i] = pBannerName[i] + "#";
pBannerTime[i] = pBannerTime[i] + rsUse.getString("DispTime") ;
szBannerTime[i] = pBannerTime[i] + ";" ;
rsUse.next();
}
for(int j=0; j<count; j++)
{
Fname = Fname + szBannerName[j];
Ftime = Ftime + pBannerName + "," + szBannerTime[j];
}
szBannerNameTime = Fname + "?" + Ftime ;
ps = conn.prepareStatement("update Reference set" + "Name = ? Where PID=C0012");
ps.setString(1, szBannerNameTime);
ps.execute();

// db를 닫는다.
ps.close();
conn.close();
System.out.println("자료 저장 완료");
}
}
catch(SQLException e)
{
System.out.println("SQL Error : " + e.getMessage());
}

}
}


다음 글들:



이어서 글올리기(답하기)

이름:
E-Mail:
제목:
내용:
HTML 태그 포함 여부: HTML 문서일 경우 체크
관련 URL(선택):
URL 제목(선택):
관련 이미지 URL:


[ 다음 글들 ] [ 이어서 글올리기(답하기) ] [ 자바 묻고 답하기 ]