TBD.my

Full Version: nk compare statement nie
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
salam....

saya nk mintak bantuan rakan2..

saya nk compare statement nie utk kalau dyer ader input dari database, bru dyer execute statement button1.setBackground(color.red) ....kalu dyer xder input x nk kasi dyer execute code bawah2 ....

skrg nie dyer sentiasa executed jer...

mintak tlg..

Quote:if ((stmt.execute("select `rule_id` from `alert` where location_id= "+pc1) ) && (stmt.execute("select `rule_id` from `alert` where timestamp="+1337193472)))

{
button1.setBackground(Color.red);

}
kalau ade if, kena ada else.. dlm else tu masukkan something error..
susah nk explain.. xpndai sgt..hehe
yang aku nampak bila kau panggil dari database, kau tak assign dia dgn mana2 value, so cam takleh compare,

cadangan aku, get data from database, assign to a value, then compare, nampak teratur sket kot...
tu yg biasa aku buat punFuck That Shit
Quote: query = "select `rule_id` from `alert` where location_id= "+pc1;

rs = stmt.executeQuery(query);


if (rs != null)

{

rs = stmt.getResultSet();
button1.setBackground(Color.red);

}

ok da ubah jadi cam nie...tpi x dpt execute plak setbackground 2...ader cdgn?

aku rasa ko tak set button1 tuh...
cuba guna JButton component...

Java class java.awt.Color tu jangan lupa masukkan nanti...

Then cuba kod

JButton btn = new JButton("Nama Butang");
button1.setBackground(Color.RED);

Harap dapat membantu.
(30-05-2012, 06:43 PM)sno0p Wrote: [ -> ]aku rasa ko tak set button1 tuh...
cuba guna JButton component...

Java class java.awt.Color tu jangan lupa masukkan nanti...

Then cuba kod

JButton btn = new JButton("Nama Butang");
button1.setBackground(Color.RED);

Harap dapat membantu.
Maksudnya coding x de error tapi cuma background button tu je la x tukar.klu x tukar cuba letak validate() and repaint()

Code:
button1.setBackground(Color.RED);
    repaint();
    validate();

contoh sebelum tu ko dh set button1 tu background dia color grey.
lepas dia execute if statement tu kalau ada value dia akan tukar background button1 jadi red.
so..kalau ko nk ubah ape2..mostly ko kena validate().validate ni untuk dia refresh kembali JFrame

x pn klu x leh..cuba ko paste coding gui ko.

tq bro for rep....saya da dpt taw nper mslh...tpi xtaw aper dyer solution dyer ag...maser saya query database, return value yg sepatutnya null dyer x detect sebgai null...dyer detect sebagai value jugak...walaupun nilai dyer xder aper2 still baca sebagai null juga...


cth:
Quote:query = "select `rule_id` from `alert` where location_id=1000";

rs = stmt.executeQuery("select `server_id` from `agent`");

dalam crite nie...location id xder smpi 100.,so dyer akan retrun null ptnyer...tpi dyer x return null n x return error...just return xder mende n but x return null...
(31-05-2012, 12:28 AM)crashman_xx Wrote: [ -> ]tq bro for rep....saya da dpt taw nper mslh...tpi xtaw aper dyer solution dyer ag...maser saya query database, return value yg sepatutnya null dyer x detect sebgai null...dyer detect sebagai value jugak...walaupun nilai dyer xder aper2 still baca sebagai null juga...


cth:
Quote:query = "select `rule_id` from `alert` where location_id=1000";

rs = stmt.executeQuery("select `server_id` from `agent`");

dalam crite nie...location id xder smpi 100.,so dyer akan retrun null ptnyer...tpi dyer x return null n x return error...just return xder mende n but x return null...

susah nk ckpla bro sbb x leh nk tgk ko punya coding..kalo ko leh share kt sini ko nya coding yang nk connect database tu leh aku try godek2 tgk.

Maksud ko bila ko query from database kalau location id lebih dari sepatutnya dia akan return null and return error.contoh database ko ada location smpai 100, bila ko query lebih dari 100 dia akan return null and error ke???
salam..saya dah dpt solution nyer..sy gune multipleif dalam satu rs...yg maner x boley jadik...tq pada semua yg sudi bantu...