JAVA class [message #532405] |
Tue, 22 November 2011 06:07 |
|
wtfn00b
Messages: 115 Registered: October 2011 Location: Latvia
|
Senior Member |
|
|
Good day, I have created this code and I want to ask whats wrong with it ? You can search in code // error: tags - where I wrote error exceptions. Please guide me to the working code.
package uploadfile;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.sql.Blob;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.activation.DataHandler;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.DataSource;
import javax.xml.bind.annotation.XmlMimeType;
import javax.xml.ws.BindingType;
import javax.xml.ws.soap.MTOM;
import javax.xml.ws.soap.SOAPBinding;
@WebService(serviceName = "TestService", portName = "TestPort")
@BindingType(SOAPBinding.SOAP12HTTP_BINDING)
@MTOM
public class TestServiceBean {
private DataSource ds;
@WebMethod
public TestServiceBean() {
@WebParam(name = "id")
BigDecimal id;
@WebParam(name = "filename")
String filename;
@WebParam(name = "data")
@XmlMimeType("application/octet-stream")
DataHandler data;
throws; // error: Unexpected token throws.
// Type or variable 'throws' not found.
// Not valid expression statement.
FileNotFoundException; // error: Not a valid expression statement
IOException; // error: Not a valid expression statement
{
try {
String os = null;
Connection conn = null;
try {
InputStream is = data.getInputStream();
StringBuffer fileData = new StringBuffer(1000);
//byte[] buffer = new byte[2048];
char[] buffer = new char[2048];
int i;
while ((i = is.read(buffer)) != -1) {
// error: 'read(char[])' cannot invoke 'read(byte[])' in 'InputStream'
fileData.append(buffer, 0, i);
}
String abcBlob = fileData.toString();
System.out.println("abcBlob = " + abcBlob);
Context ic = new InitialContext();
ds = (DataSource)ic.lookup("jdbc/DISWSDS");
conn = ds.getConnection();
BigDecimal idValue = null;
try {
PreparedStatement stmt =
conn.prepareStatement("SELECT id FROM JANIS.table WHERE idFile = 123");
stmt.setBigDecimal(1, ??? ); // error: what I need to put here ?
ResultSet rs = stmt.executeQuery();
while (rs.next()) {
idValue = rs.getBigDecimal(1);
}
PreparedStatement stmt2 =
conn.prepareStatement("INSERT INTO JANIS.uploadedfiles VALUES ('+ idValue +', '+ abcBlob +')");
stmt2.executeQuery();
conn.commit();
} catch (Exception e) {
conn.rollback();
throw e;
throw new RuntimeException(e);
}
} finally {
if (conn != null)
try {
conn.close();
} catch (Exception ignore) {
}
}
} catch (Exception e) {
e.printStackTrace();
//throw e ;
}
}
}
}
Best regards,
wtfn00b.
|
|
|
|
|
|
|
|
|
|
Re: JAVA class [message #532419 is a reply to message #532418] |
Tue, 22 November 2011 07:01 |
|
Michel Cadot
Messages: 68731 Registered: March 2007 Location: Saint-Maur, France, https...
|
Senior Member Account Moderator |
|
|
This question bears no real connection with Oracle.
Please find a more appropriate forum.
The topic is locked.
If I'm wrong, please, PM me (or report this message to a moderator, explain why you think it should be unlocked and it might be done).
Regards
Michel
|
|
|