Home » Developer & Programmer » JDeveloper, Java & XML » JAVA class (11.2.0.1.0 - Production, jdeveloper 11g R2 11.1.2.1.0, Win7 Prof. 64-bit, Weblogic server)
JAVA class [message #532405] Tue, 22 November 2011 06:07 Go to next message
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 #532410 is a reply to message #532405] Tue, 22 November 2011 06:35 Go to previous messageGo to next message
Littlefoot
Messages: 21806
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
Quote:
I want to ask whats wrong with it

Why do you think that there's something wrong with it?
Re: JAVA class [message #532412 is a reply to message #532405] Tue, 22 November 2011 06:37 Go to previous messageGo to next message
Michel Cadot
Messages: 68625
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Quote:
I want to ask whats wrong with it


It is not PL/SQL.

Regards
Michel
Re: JAVA class [message #532413 is a reply to message #532410] Tue, 22 November 2011 06:41 Go to previous messageGo to next message
wtfn00b
Messages: 115
Registered: October 2011
Location: Latvia
Senior Member
Because it's have errors. I think it's not good written.
Please tell me what's wrong with it.
In code you can see lines with errors:

DataHandler data;
        throws; // error: Unexpected token throws.
        // Type or variable 'throws' not found.
        // Not valid expression statement.


FileNotFoundException; // error: Not a valid expression statement


while ((i = is.read(buffer)) != -1) {
// error: 'read(char[])' cannot invoke 'read(byte[])' in 'InputStream'
fileData.append(buffer, 0, i);
}


IOException; // error: Not a valid expression statement


 stmt.setBigDecimal(1, ??? ); // error: what I need to put here ?


Regards,
wtfn00b.
Re: JAVA class [message #532414 is a reply to message #532413] Tue, 22 November 2011 06:52 Go to previous messageGo to next message
Michel Cadot
Messages: 68625
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
How is this related to Oracle?

Regards
Michel
Re: JAVA class [message #532415 is a reply to message #532414] Tue, 22 November 2011 06:53 Go to previous messageGo to next message
Littlefoot
Messages: 21806
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
Quote:
Because it's have errors. I think it's not good written.

Right, but - how is anyone supposed to know what errors? You never specified any. (Aside the fact that I don't know Java, but - generally speaking, you should explain the problem, not expect someone else to figure it out).
Re: JAVA class [message #532417 is a reply to message #532414] Tue, 22 November 2011 06:56 Go to previous messageGo to next message
wtfn00b
Messages: 115
Registered: October 2011
Location: Latvia
Senior Member
I'm using Oracle database. JDBC connection is use in Java class.
It's not PL/SQL but simple SQL.

Regards,
wtfn00b.
Re: JAVA class [message #532418 is a reply to message #532417] Tue, 22 November 2011 07:00 Go to previous messageGo to next message
wtfn00b
Messages: 115
Registered: October 2011
Location: Latvia
Senior Member
Okey, sorry, I have problem:
1) That I don't know why it's telling me the errors and I don't know how to fix theim Sad
2) I don't know how to correctly use byte [] to string while cycle, looked in google but it's not working correct;

Regards,
wtfn00b.
Re: JAVA class [message #532419 is a reply to message #532418] Tue, 22 November 2011 07:01 Go to previous message
Michel Cadot
Messages: 68625
Registered: March 2007
Location: Nanterre, France, http://...
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
Previous Topic: file to base64
Next Topic: JDeveloper error
Goto Forum:
  


Current Time: Thu Mar 28 13:40:31 CDT 2024