Konuyu görüntüle
IUCODERS FORUM > Programlama > JAVA > Javadan store procedure çağıramıyorum
Yazar
tugba7203


avatar
konya
Kayıt: 12.05.2013
13.05.2013-02:24 #78838
create procedure eczaciekle
@adi nvarchar(50)
@soyadi nvarchar(50)
@tcno nvarchar(50)
@sicilno nvarchar(50)
@kayittarihi nvarchar(50)
@kadi nvarchar(50)
@sifre nvarchar(50)
as
insert into dbo.eczaci(adi,soyadi,tcno,sicilno,kayittarihi,kadi,sifre) values(@adi,@soyadi,@tcno,@sicilno,@kayittarihi,@kadi,@sifre)

bu şekilde fakat javadan bir türlü çağıramadm.yardımcı olursanız sevinirim





Yazar
tugba7203


avatar
konya
Kayıt: 12.05.2013
13.05.2013-02:25 #78839
değerlerimi edittextten alacağım





Yazar
extreme


avatar
Kahramanmaras
admin
Kayıt: 24.10.2006
13.05.2013-09:52 #78840
Şu fonksiyonlar işini görecektir. Javadoc kısmında nasıl kullanılacağı bilgisi var.

/**
     * Executes a procedure on database.
     *
     * Use {@link #getCon()} to get a connection.
     *
     * @param procedure The procedure which will be executed. Using like "{call
     * procedure()"
     * @exception Exception
     */
    public Boolean executeProcedure(String procedure) throws DBException {
        Connection con = null;
        try {
            con = getConnection();
            PreparedStatement pst = con.prepareCall(procedure);
            return pst.execute();
        } catch (DBException ex) {
            throw new DBException(ex);
        } catch (SQLException ex) {
            throw new DBException(ex);
        } catch (Exception ex) {
            throw new DBException(ex);
        } finally {
            releaseCon(con);
        }
    }

    /**
     * Executes a procedure on database.
     *
     * Use {@link #getCon()} to get a connection.
     *
     * @param procedure Procedure which will be executed. Using like "{call
     * procedure(?,?)"
     * @param args objects needed in query
     * @exception Exception
     */
    public Boolean executeProcedure(String procedure, Object... args) throws DBException {
        Connection con = null;
        try {
            con = getConnection();
            CallableStatement pst = con.prepareCall(procedure);
            for (int i = 0; i < args.length; i++) {
                pst.setObject(i + 1, args[i]);
            }
            return pst.execute();
        } catch (DBException ex) {
            throw new DBException(ex);
        } catch (SQLException ex) {
            throw new DBException(ex);
        } catch (Exception ex) {
            throw new DBException(ex);
        } finally {
            releaseCon(con);
        }
    }
/**
     * Return result from database.
     *
     * Use {@link #getCon()} to get a connection.
     *
     * @param sqlQuery Query which will be retuned
     * @return ResultSet
     * @exception Exception
     */
    public ResultSet returnProcedureResult(final String sqlQuery) throws DBException {

        Connection con = null;
        try {
            con = getConnection();
            CallableStatement pst;
            if (con != null && !con.isClosed()) {
                pst = con.prepareCall(sqlQuery);
            } else {
                throw new DBException("Connection is closed");
            }
            return pst.executeQuery();
        } catch (DBException ex) {
            throw new DBException(ex);
        } catch (SQLException ex) {
            throw new DBException(ex);
        } catch (Exception ex) {
            throw new DBException(ex);
        } finally {
            releaseCon(con);
        }
    }

    /**
     * Return result from database.
     *
     * Use {@link #getCon()} to get a connection.
     *
     * @param sqlQuery Query which will be retuned
     * @param args Objects needed in sqlQuery
     * @return ResultSet
     * @exception Exception
     */
    public ResultSet returnProcedureResult(final String sqlQuery, Object... args) throws DBException {

        Connection con = null;
        try {
            con = getConnection();
            CallableStatement pst;
            if (con != null && !con.isClosed()) {
                pst = con.prepareCall(sqlQuery);
            } else {
                throw new DBException("Connection is closed");
            }
            for (int i = 0; i < args.length; i++) {
                pst.setObject(i + 1, args[i]);
            }
            return pst.executeQuery();
        } catch (DBException ex) {
            throw new DBException(ex);
        } catch (SQLException ex) {
            throw new DBException(ex);
        } catch (Exception ex) {
            throw new DBException(ex);
        } finally {
            releaseCon(con);
        }
    }






The Man Who Loved Algorithm&Ubuntu.
www.burakamasyali.com





Yazar
extreme


avatar
Kahramanmaras
admin
Kayıt: 24.10.2006
13.05.2013-09:56 #78841
Senin örneğin şöyle olmalı:
executeProcedure("{call eczaciekle(?,?,?,?,?,?,?)}",adi,soyadi,tcno,sicilno,kayittarihi,kadi,sifre);






The Man Who Loved Algorithm&Ubuntu.
www.burakamasyali.com





Yazar
tugba7203


avatar
konya
Kayıt: 12.05.2013
13.05.2013-21:48 #78844
teşekkür ederim birşey daha sormak istiyorum.Yukarıdaki kodları yazdığım zaman Must declare the scalar variable @adi , Must declare the scalar variable @soyadi... şeklinde hata alıyorum.Java tarafında çalıştırdığımda ise procedure eklediğim halde Could not find stored procedure 'eczaciekle' hatyı alıyorum.





Yazar
extreme


avatar
Kahramanmaras
admin
Kayıt: 24.10.2006
15.05.2013-09:36 #78846
Bu veritabanı tarafında çözmeniz gereken bir problem.





The Man Who Loved Algorithm&Ubuntu.
www.burakamasyali.com





Yazar
pierini


avatar

Kayıt: 05.02.2007
26.05.2013-01:49 #78873
extreme in yazdigi ornekte, procedure un oldugu paket ismini de eklemeyi deneyebilirsin.

paketAdi.eczaciEkle seklinde cagirip parametre sayisi kadar da soru isareti eklemen gerek. olmazsa db.connect var mi onu kontrol etmelisin. cok eski ve soru isaretleriyle bolca kafa yedirten bir metot. kolay gelsin :)

tugba7203 yazdi
 
teşekkür ederim birşey daha sormak istiyorum.Yukarıdaki kodları yazdığım zaman Must declare the scalar variable @adi , Must declare the scalar variable @soyadi... şeklinde hata alıyorum.Java tarafında çalıştırdığımda ise procedure eklediğim halde Could not find stored procedure 'eczaciekle' hatyı alıyorum.






never stop # if you run
never attempt # if you stop












Del.icio.us
Digg
Facebook
Furl
Google
Blink
Simpy
Spurl
Y! MyWeb