i'm working on java project , far going i'm stuck @ problem. have working connection database <-> program, have working login (users , pws in database) ... app parking system... in database have 1 table "upravljanje" (eng. control) have 1 row , 4 columns (now, max, cijenah, oznaka) (eng. cars in parking now, max capacity, price per hour, , id = 1) integers
other stuff working (they're strings , think that's prob)
this code of problem
public static upravljanje dohvatiupravljanje(){ try{ connection conn = kreirajkonekciju(); statement stmt = conn.createstatement(); string sql = "select * upravljanje;"; resultset rs = stmt.executequery(sql); upravljanje upravljanje = new upravljanje(rs.getint("max"), rs.getint("now"), rs.getint("cijenah")); system.out.println("proba - max - - cijenah :"+rs.getint("max")); conn.close(); return upravljanje; }catch(exception e){ system.out.println("greska kod dohvacanja podataka o parkingu iz baze: "+e.tostring()); return null; } }
and red console
> greska kod dohvacanja podataka o parkingu iz baze: java.sql.sqlexception: before start of result set java.lang.nullpointerexception @ view.upravljanjeframe.<init>(upravljanjeframe.java:104) @ view.upravljanjeframe$1.run(upravljanjeframe.java:38) @ java.awt.event.invocationevent.dispatch(unknown source) @ java.awt.eventqueue.dispatcheventimpl(unknown source) @ java.awt.eventqueue.access$500(unknown source) @ java.awt.eventqueue$3.run(unknown source) @ java.awt.eventqueue$3.run(unknown source) @ java.security.accesscontroller.doprivileged(native method) @ java.security.protectiondomain$javasecurityaccessimpl.dointersectionprivilege(unknown source) @ java.awt.eventqueue.dispatchevent(unknown source) @ java.awt.eventdispatchthread.pumponeeventforfilters(unknown source) @ java.awt.eventdispatchthread.pumpeventsforfilter(unknown source) @ java.awt.eventdispatchthread.pumpeventsforhierarchy(unknown source) @ java.awt.eventdispatchthread.pumpevents(unknown source) @ java.awt.eventdispatchthread.pumpevents(unknown source) @ java.awt.eventdispatchthread.run(unknown source)
please can me...
ps return "null" can me put smarter?
you have call .next() resultset, i.e.:
resultset rs = stmt.executequery(sql); if (rs.next()) { upravljanje upravljanje = new upravljanje(rs.getint("max"), rs.getint("now"), rs.getint("cijenah")); ... }
or change 'if' 'while' in case expect multiple results. rs.getxxx return fields current row.
Comments
Post a Comment