Java Switch Case Error -
i'm here trying switch case send data jtable althoug runs case x, doesn't send table. put code here , apreciate if guys me.
function switch case
private void gerar(int x) { defaulttablemodel model = (defaulttablemodel) jtable1.getmodel(); model.setrowcount(0); connection conn = null; statement stmt = null; switch (x) { case 1: system.out.println("case 1"); jtable1.setmodel(new javax.swing.table.defaulttablemodel( new object[][]{}, new string[]{ "utilizador", "password" } ) { boolean[] canedit = new boolean[]{ false, false }; public boolean iscelleditable(int rowindex, int columnindex) { return canedit[columnindex]; } }); model.setrowcount(0); try { system.out.println("try 1"); class.forname("com.mysql.jdbc.driver"); conn = drivermanager.getconnection(db_url, user, pass); stmt = conn.createstatement(); string sql = "select * login"; resultset rs = stmt.executequery(sql); while (rs.next()) { string idd = rs.getstring("utilizador"); string pass = rs.getstring("password"); model.addrow(new object[]{idd, pass}); } system.out.println("while 1"); rs.close(); stmt.close(); conn.close(); } catch (sqlexception | classnotfoundexception se) { se.printstacktrace(); } { if (stmt != null) { try { stmt.close(); } catch (sqlexception ex) { ex.printstacktrace(); } } if (conn != null) { try { conn.close(); } catch (sqlexception ex) { ex.printstacktrace(); } } } break; case 2: break; case 3: break; case 4: break; case 5: break; case 6: system.out.println("case 6"); jtable1.setmodel(new javax.swing.table.defaulttablemodel( new object[][]{}, new string[]{ "sigla", "nome", "faltas justc", "faltas injustc", "faltas justs", "faltas injusts", "dataini", "datafim", "email" } ) { boolean[] canedit = new boolean[]{ false, false }; public boolean iscelleditable(int rowindex, int columnindex) { return canedit[columnindex]; } }); model.setrowcount(0); try { system.out.println("try 6"); class.forname("com.mysql.jdbc.driver"); conn = drivermanager.getconnection(db_url, user, pass); stmt = conn.createstatement(); string sql = "select * cursos"; resultset rs = stmt.executequery(sql); while (rs.next()) { string idd = rs.getstring("sigla"); string pass = rs.getstring("nome"); int fjc = rs.getint("faltasjustificadasc"); int fijc = rs.getint("faltasinjustificadasc"); int fjs = rs.getint("faltasjustificadass"); int fijs = rs.getint("faltasinjustificadass"); int di = rs.getint("data_inicio"); int df = rs.getint("data_fim"); string em = rs.getstring("email"); model.addrow(new object[]{idd, pass, fjc, fijc, fjs, fijs, di, df, em}); } system.out.println("while 6"); rs.close(); stmt.close(); conn.close(); } catch (sqlexception | classnotfoundexception se) { se.printstacktrace(); } { if (stmt != null) { try { stmt.close(); } catch (sqlexception ex) { ex.printstacktrace(); } } if (conn != null) { try { conn.close(); } catch (sqlexception ex) { ex.printstacktrace(); } } } break; case 7: break; case 8: break; case 9: break; case 10: break; case 11: break; case 12: break; default: break; } } }
what calls it
private void jbutton10actionperformed(java.awt.event.actionevent evt) { sv(); gerar(1); id1.seteditable(false); n1.settext("utilizador:"); n2.settext("password:"); n3.setvisible(false); n4.setvisible(false); n5.setvisible(false); n6.setvisible(false); n7.setvisible(false); n8.setvisible(false); n9.setvisible(false); nn3.setvisible(false); nn4.setvisible(false); nn5.setvisible(false); nn6.setvisible(false); nn7.setvisible(false); nn8.setvisible(false); nn9.setvisible(false); }
it doesn't send table because
jtable1.setmodel(new javax.swing.table.defaulttablemodel( new object[][]{}, new string[]{ "utilizador", "password" } ) { boolean[] canedit = new boolean[]{ false, false }; public boolean iscelleditable(int rowindex, int columnindex) { return canedit[columnindex]; } });
does create new tablemodel table. when later go ahead , add rows existing model named 'model', nobody cares because it's not model table anymore anyway.
Comments
Post a Comment