Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

Tomcat, Postgres, jsp, invalid column name .. ali ne uvek

[es] :: Java :: Tomcat, Postgres, jsp, invalid column name .. ali ne uvek

[ Pregleda: 1458 | Odgovora: 3 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

Shejn
Srbija

Član broj: 11830
Poruke: 232
*.dynamic.sbb.rs.



Profil

icon Tomcat, Postgres, jsp, invalid column name .. ali ne uvek10.11.2010. u 08:29 - pre 163 meseci
Pozdrav.

Imam problem sa izvrsavanjem sql-a
Code:

select * from sessions ses
left join korisnici using (id_korisnika)
where session_id = 'neki-session-id';

greska koja se javlja je: SQLException: Invalid column name .. ali je ustvari veci problem sto se greska ne javlja uvek.

Code:

    CachedRowSetImpl crs = null;
    try {

        sqlstr = "SELECT * FROM  sessions ses "
                + "LEFT JOIN korisnici kor USING (id_korisnika) "
                + "WHERE ses.session_id = '" + session_id + "' ";
        crs = db.executeQuery(sqlstr, 0);
        crs.last();
        int broj_slogova = crs.getRow();
        if (broj_slogova == 0) {
             return "BEZ_PRIJAVE|-";
        }

        str_check_time = crs.getString("check_time"); <<< zvekete!!

       .....
   } catch (SQLException ex) {
      System.out.println("[" + new java.util.Date() + "]\nSQLException: " + ex.getMessage()
   }

/////////////
/// class db
/////////////
public static CachedRowSetImpl executeQuery(String query, int tip) {
        Connection conn = null;
        Statement st = null;
        ResultSet rs = null;

        try
        {
            conn = getConnection();

            switch (tip)
            {
                case 0://SELECT
                    st = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
                    rs = st.executeQuery(query);

                    crs = new CachedRowSetImpl();
                    crs.populate(rs);

                    break;

                default://INSERT, UPDATE, or DELETE
                    st = conn.createStatement();
                    st.executeUpdate(query);
                    break;

            }
            
        } catch (SQLException ex)
        {
            System.out.println("[" + new java.util.Date() + "] GRESKA PRILIKOM IZVRSAVANJA SQL UPITA!\n" + query +"\nOPIS GRESKE:\n"+ ex);
        }

        try
        {
            if (st != null)
            {
                st.close();
            }
            if (rs != null)
            {
                rs.close();
            }

            if (conn != null)
            {
                freeConnection(conn);
            }
        } catch (Exception e)
        {
            e.printStackTrace();
        }


        return crs;

    }

    public static synchronized void freeConnection(Connection connection) {
        try
        {
            if (connection != null)
            {
                connection.close();
            }
            connection = null;
        } catch (Exception e)
        {
            System.err.println("DBBroker: Threw an exception closing a database connection");
            e.printStackTrace();
        }
    }



Kao sto sam napomenu, program radi dobro .. ali se svremena na vreme pojavi u logu ovaj sql exception.
Jel ima neko neki predlog?

Hvala.
 
Odgovor na temu

dule_ns
Novi Sad

Član broj: 123863
Poruke: 257
194.247.212.*



+690 Profil

icon Re: Tomcat, Postgres, jsp, invalid column name .. ali ne uvek10.11.2010. u 09:47 - pre 163 meseci
A zašto štrikaš sql?

Bolje da koristiš Prepared statement i da mu prosleđuješ parametar.

Što se tiče tvog koda, moguće da je problem u tome što ne proveravaš da li ti je
crs.last();
vratio true ili false. U dokumentaciji piše:

Citat:
Returns:
true if the cursor is on a valid row; false otherwise or if there are no rows in this CachedRowSetImpl object


Mada sad vidim da imaš onaj getRow(); Jbg, ne znam, ali zaista bolje izmeni i prosleđuj parametre umesto što štrikaš sql i parametre ubaciuješ direktno u SQL.

[Ovu poruku je menjao dule_ns dana 10.11.2010. u 11:07 GMT+1]
 
Odgovor na temu

grizzly
Beograd

Član broj: 7978
Poruke: 262



+4 Profil

icon Re: Tomcat, Postgres, jsp, invalid column name .. ali ne uvek10.11.2010. u 10:37 - pre 163 meseci
Mozda ti za session-id, ako je to nesto sto ti generises ili tako nesto, dodje neki string koji ima u sebi neki karakter recimo ' koji ti zezne upit. To bi objasnilo zasto se ponekad desi a ponekad ne.
 
Odgovor na temu

Shejn
Srbija

Član broj: 11830
Poruke: 232
*.dynamic.sbb.rs.



Profil

icon Re: Tomcat, Postgres, jsp, invalid column name .. ali ne uvek10.11.2010. u 10:43 - pre 163 meseci
session_id je id sessije koju dobijam od servleta

Code:

       if ((session = request.getSession(false)) == null) {
            session = request.getSession(true);
            session_id = session.getId();
             System.out.println("[" + new java.util.Date() + "]\nKREIRANJE NOVE SESIJE");
       } else {
             session_id = session.getId();
             System.out.println("[" + new java.util.Date() + "]\nSTARA SESIJA");
       }


Citat:
dule_ns:
Bolje da koristiš Prepared statement i da mu prosleđuješ parametar.

razmislicu o ovome, mada mislim da nije tu problem.
 
Odgovor na temu

[es] :: Java :: Tomcat, Postgres, jsp, invalid column name .. ali ne uvek

[ Pregleda: 1458 | Odgovora: 3 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.