1. #1
    Sencha User talha06's Avatar
    Join Date
    Jul 2009
    Location
    Turkey
    Posts
    303
    Vote Rating
    0
    talha06 is on a distinguished road

      0  

    Exclamation [Java] Returning JSON Array from DB to Grid Problem

    [Java] Returning JSON Array from DB to Grid Problem


    Hello everyone,

    I was using XML Reader and writing the results to XML to communicate with DB. I'm new to JSON Objects. Now I'm trying to send data(JSON Array) to back(grid).

    Here's my JSON Store:
    Code:
    var myStore = new Ext.data.JsonStore({
                       autoLoad : true,
                       //url : 'tabloDoldur.ajax',// eklenecek..
                       url : 'GetKisiler',// Servlet : DAO.KisiHelper araciligiyla veri cekiyor..
                       fields : myRecords,
                       idProperty : 'kisiId',
                       totalProperty : 'totalCount',
                       root : 'data',
                       sortInfo : {
                           field : 'kisiId',
                           direction : 'DESC'
                       }
                    });

    Here's my servlet code for this :
    Code:
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            List<Kisi2> kisiList = null;
            JSONArray arr = null;
            Kisi2 k = null;
            try {
                Class.forName("oracle.jdbc.OracleDriver").newInstance();
                Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","talha", "00");            
                Statement st = con.createStatement();
                String sql = "select * from kisi";
                kisiList = new ArrayList<Kisi2>();
                arr = new JSONArray();
                ResultSet rs = st.executeQuery(sql);
                while(rs.next()) {
                    k = new Kisi2();  // 'Kisi2' is a basic class that just includes variables like id, kisiId, kisiAd, etc.
                    k.id = rs.getInt("ID");
                    k.kisiId = rs.getInt("KISI_ID");
                    k.kisiAd = rs.getString("KISI_AD");
                    k.kisiSoyad = rs.getString("KISI_SOYAD");
                    k.kisiYas = rs.getInt("KISI_YAS");
                    k.kisiCinsiyet = rs.getString("KISI_CINSIYET");
                    k.kisiMeslek = rs.getString("KISI_MESLEK");
                    
                    boolean sonuc = kisiList.add(k);
                    if(sonuc) {
                        System.out.println(k.kisiAd + " kisisi listeye eklendi");
                    } else {
                        System.out.println("Kisi EKLENEMEDI!!");
                    }
                    arr.put(kisiList);
                }
                //arr = JSONArray.fromObject(kisiList);
                response.getWriter().write(arr.toString());
                rs.close();
                st.close();
                con.close();
            } catch(Exception e) {
                e.printStackTrace();
            }
        }

  2. #2
    Sencha User realjax's Avatar
    Join Date
    Aug 2009
    Location
    Netherlands
    Posts
    412
    Vote Rating
    6
    realjax is on a distinguished road

      0  

    Default


    And your question would be ...?

  3. #3
    Sencha User talha06's Avatar
    Join Date
    Jul 2009
    Location
    Turkey
    Posts
    303
    Vote Rating
    0
    talha06 is on a distinguished road

      0  

    Default


    Quote Originally Posted by realjax View Post
    And your question would be ...?
    I'm asking my mistake in server side code. (Java) And I want to do this in the best way; maybe using AJAX requests.
    Thanx for reply.

Thread Participants: 1

film izle

hd film izle

film sitesi

takipci kazanma sitesi

takipci kazanma sitesi

güzel olan herşey

takipci alma sitesi

komik eğlenceli videolar