0

when i wrote function instead of procedure, it compiled.

CREATE OR REPLACE function ilce_gtr
(
    p_ilkodu number  
)
RETURN VARCHAR2 AS
 p_geridonen varchar2(1000);
begin
for rec in(SELECT ADI FROM ILCE WHERE Y_IL=p_ilkodu)
loop
p_geridonen := p_geridonen || '|' || rec.ADI;
end loop;
return p_geridonen;
end;
/

then i created xml via web method, it was successful.

 @WebMethod
        public String get_ilce (int p_ilkodu) {

            Statement stmt=null;
            ResultSet rs=null;
            Connection conn=null;
            String deger=null;

            try {
              conn= getConnection_test();
              String query = "SELECT ILCE_GTR('" + p_ilkodu + "') FROM DUAL";
              stmt = conn.createStatement();
              rs = stmt.executeQuery(query);
              while (rs.next()) {
               deger = rs.getString(1);                        
              }        

            } catch (Exception e) {
                return "hata";
            } finally {
              try {
                rs.close();
                stmt.close();
                conn.close();
              } catch (SQLException e) {
                return "hata";
              }          
            }            
            return deger;
        }

I want to do the same for inserting to database, can u help me?

Tobb
  • 11,850
  • 6
  • 52
  • 77
  • 1
    try logging your exceptions rather than `catch (Exception e) { return "hata"; }` – Scary Wombat Sep 09 '16 at 06:21
  • This code created and it successful but it doesnt insert to database. How can I do the insertion process? Is the stored procedure in database or web method in java? @Scary Wombat – M.Telceken Sep 09 '16 at 06:35
  • SQL should be fine e.g. `insert into table ....` – Scary Wombat Sep 09 '16 at 06:38
  • i know but where can I do the insertion process? Is the stored procedure in database or web method in java? – M.Telceken Sep 09 '16 at 07:20
  • You seriously need to google "the Single Responsibility Principle". Putting database stuiff directly into your webservice is bad, just bad. – Tobb Sep 09 '16 at 07:51

2 Answers2

0
@WebMethod
        public String add_ilce (int yourInput) {

            Statement stmt=null;
            ResultSet rs=null;
            Connection conn=null;
            String deger=null;

            try {
              conn= getConnection_test();
              String query = "INSERT INTO DUAL" + "(yourAttributeName)" +"VALUES (?)";
                  PreparedStatement preparedStmt = conn.prepareStatement(query);
                preparedStmt.setString (1, yourInput);
                preparedStmt.execute();



            } catch (Exception e) {
                return "hata";
            } finally {
              try {
                rs.close();
                stmt.close();
                conn.close();
              } catch (SQLException e) {
                return "hata";
              }          
            }            
            return deger;
        }

EDIT: I suggest you to use DAO approach for such scenarios, check here: Data access object (DAO) in Java

EDIT: I edited the post now it must work as it should be, sorry I had some mistakes

Community
  • 1
  • 1
Tano
  • 1,285
  • 1
  • 18
  • 38
0

web service didnt appear on localhost, there are others.

@WebMethod
    public String add_ilce (String p_no, int p_tplm) {

        Statement stmt=null;
        ResultSet rs=null;
        Connection conn=null;
        String deger=null;

        try {
          conn= getConnection_test();
          String query = "INSERT INTO DUAL" + "TEMP_TAHAKKUK_AG(ABONENO,TOPLAM)" +"VALUES ('p_no','p_tplm')";
          stmt = conn.createStatement();
          rs = stmt.executeQuery(query);

          while (rs.next()) {
              deger = rs.getString(1);                        
             }        
        } catch (Exception e) {
            return "hata";
        } finally {
          try {
            rs.close();
            stmt.close();
            conn.close();
          } catch (SQLException e) {
            return "hata";
          }          
        }            
        return deger;
    }