Cara... dá uma olhada na minha classe! Está bastante útil!
package pizzaria; import java.sql.*; import java.util.Vector; public class Banco { private Vector resp = new Vector(); private static Connection con = null; public Banco() { if (con == null) { try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); con = DriverManager.getConnection("jdbc:odbc:Pizzaria","",""); } catch (Exception e) { System.err.println("Erro no comando de conexao"); } } } public static Connection getConnection() { return con; } public boolean sqlQuery(String str) { Statement stmt = null; resp.clear(); boolean state = true; try{ stmt = con.createStatement(); ResultSet rs = stmt.executeQuery(str); ResultSetMetaData rsmd = rs.getMetaData(); while (rs.next()) for (int i=1;i<=rsmd.getColumnCount();i++) resp.addElement(rs.getString(i)); } catch (Exception e) { System.err.println(e.getMessage()); state = false; } finally { try { stmt.close(); } catch (Exception e) {} } return state; } public boolean sqlExecuteQuery(String str) { Statement stmt = null; resp.clear(); boolean state = true; try{ stmt = con.createStatement(); stmt.execute(str); } catch (Exception e) { System.err.println(e.getMessage()); state = false; } finally { try { stmt.close(); } catch (Exception e) {} } return state; } public boolean sqlUpdateQuery(String str) { Statement stmt = null; resp.clear(); boolean state = true; try{ stmt = con.createStatement(); stmt.executeUpdate(str); } catch (Exception e) { System.err.println(e.getMessage()); state = false; } finally { try { stmt.close(); } catch (Exception e) {} } return state; } public String[] getResultQuery() { String[] output = new String[resp.size()]; resp.copyInto(output); return output; } }
------------------------------ LISTA SOUJAVA ---------------------------- http://www.soujava.org.br - Sociedade de Usuários Java da Sucesu-SP dúvidas mais comuns: http://www.soujava.org.br/faq.htm regras da lista: http://www.soujava.org.br/regras.htm historico: http://www.mail-archive.com/java-list%40soujava.org.br para sair da lista: envie email para [EMAIL PROTECTED] -------------------------------------------------------------------------