2012-11-19 6 views
0

다음 코드를 사용하여 데이터베이스에 파일을 업로드합니다. 코드는 이미지와 함께 정상적으로 작동합니다. 다른 파일의 경우 작동하지 않습니다. 마지막으로 스택 추적을 게시합니다.데이터베이스에 파일을 업로드 할 수 없습니다.

내 두 번째 값은 BLOB에게 있습니다

String strFilePath = null; 
    Hashtable<Object,Object> fileTable = null; 
    InputStream input = null; 
    CosUploadFile file = null; 

fileTable = multiPartFormData.getFiles(); 
file = (CosUploadFile)fileTable.get("filepath"); 
input =file.getInpuStream(); 

prepare = connection.prepareStatement("insert into all_files values(?,?,?)"); 
prepare.setString(1, strFileSplit[0]); 
prepare.setBinaryStream(2,input); 
prepare.setString(3,strFileSplit[1]); 
prepare.execute(); 

오류 :

J2CA0206W: A connection error occurred. To help determine the problem, enable the Diagnose Connection Usage option on the Connection Factory or Data Source. 
J2CA0056I: The Connection Manager received a fatal connection error from the Resource Adapter for resource datasource. The exception is: java.sql.SQLRecoverableException: Io exception: Connection reset by peer: socket write error:java.net.SocketException: Connection reset by peer: socket write error 
    com.ibm.websphere.ce.cm.StaleConnectionException: Io exception: Connection reset by peer: socket write error 

이 나는 ​​문서 파일을 업로드하기 위해 노력하고있어 동안 스택 추적입니다. 어떻게해야합니까?

편집 : 다음 내 연결 코드

DBConnect dbConnect = new DBConnect(); 
Connection connection = dbConnect.connect(); 

DbConnect 클래스

public Connection connect() 
    { 
    Connection con = null; 
    try 
    { 
    InitialContext context = new InitialContext(); 
    DataSource datasource = (DataSource)context.lookup("datasource"); 
    con = datasource.getConnection("TRAIN2012", "xyz123"); 
    return con; 
    } 
+0

Oracel 데이터베이스에 연결 하시겠습니까? 다른 데이터베이스는 무엇입니까? – bonCodigo

+1

이미지 나 기타 파일을 저장하는 경우에는 차이가 발생하지 않습니다. 코드 한 번에 하나의 파일 만 테스트하십시오. – Kai

+0

오라클의 얇은 드라이버 10 – sagar

답변

1

그러나 파일 시스템에 이미지를 저장하는 것이 더 나은 다음에 시도의 위치를 ​​저장 데이타베이스 내의 파일 이에 대한 토론은 here입니다.

FileInputStream fis = null; 

File image = new File("\\yourpath\test.PNG"); 
fis = new FileInputStream(image); 
prepare.setBinaryStream(2,fis,(int)image.length()); 
prepare.execute(); 
+0

웹 응용 프로그램을 사용하고 있는데 클라이언트 측 주소를 가져올 수 없어서 사용할 수 없습니다. – sagar

+0

@sagar 클라이언트 측 주소가 의미하는 바는 무엇입니까? 더 자세히 설명해 주시겠습니까? – user75ponic

+0

사용자는 새 브라우저에서 허용되지 않으므로 로컬 시스템이됩니다. – sagar

관련 문제