Guest User

Untitled

a guest
Apr 10th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.66 KB | None | 0 0
  1. /*
  2. * To change this template, choose Tools | Templates
  3. * and open the template in the editor.
  4. */
  5.  
  6. package teste;
  7.  
  8. import java.sql.Connection;
  9. import java.sql.DriverManager;
  10. import java.sql.ResultSet;
  11. import java.sql.Statement;
  12. import java.util.logging.Level;
  13. import java.util.logging.Logger;
  14. import javax.swing.JOptionPane;
  15.  
  16. public class Controle_1 {
  17.  
  18. private Connection con;
  19. private Statement statement;
  20. private ResultSet rs;
  21.  
  22. public String[][] procurarPessoa(String descricao,String estado) {
  23. rs = null;
  24. String[][] dados = null;
  25. String Hd = "C:\\Users\\Aluno\\Desktop\\banco.mdb";
  26. try {
  27. Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  28. Connection con= DriverManager.getConnection("jdbc:odbc:Driver=" +
  29. "{Microsoft Access Driver (*.mdb)};" +
  30. "DBQ=" + Hd ,"","");
  31. statement = con.createStatement();
  32. String s = null;
  33. if(descricao !=null || !descricao.equals(""))
  34. s= "select p.codigo,p.nome,endereco,e.nome from pessoa p,estado_civil e where p.estado_civil = e.codigo and p.nome like '%" + descricao + "%'";
  35. else
  36. s= "select p.codigo,p.nome,endereco,e.nome from pessoa p,estado_civil e where p.estado_civil = e.codigo";
  37. s = s + " and estado_civil =" + new Integer(estado).intValue();
  38. rs = statement.executeQuery(s);
  39. ResultSetTableModel rst = new ResultSetTableModel("sun.jdbc.odbc.JdbcOdbcDriver",
  40. "jdbc:odbc:Driver=" +
  41. "{Microsoft Access Driver (*.mdb)}; DBQ=" + Hd, "", "",
  42. s);
  43. dados = new String[rst.getRowCount()][4];
  44. int aux = 0;
  45. while (rs.next()) {
  46. dados[aux][0] = rs.getString(1);
  47. dados[aux][1] = rs.getString(2);
  48. dados[aux][2] = rs.getString(3);
  49. dados[aux][3] = rs.getString(4);
  50. aux++;
  51. }
  52. } catch (Exception ex) {
  53. Logger.getLogger(Controle.class.getName()).log(Level.SEVERE, null, ex);
  54. }
  55. return dados;
  56. }
  57.  
  58.  
  59. public String[][] procurarProduto(String descricao) {
  60. rs = null;
  61. String[][] dados = null;
  62. String Hd = "C:\\Users\\Aluno\\Desktop\\banco.mdb";
  63. try {
  64. Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  65. Connection con= DriverManager.getConnection("jdbc:odbc:Driver=" +
  66. "{Microsoft Access Driver (*.mdb)};" +
  67. "DBQ=" + Hd ,"","");
  68. statement = con.createStatement();
  69. String s = null;
  70. if(descricao !=null || !descricao.equals(""))
  71. s= "select * from Produto where nome like '%" + descricao + "%'";
  72. else
  73. s = "select * from Produto";
  74. rs = statement.executeQuery(s);
  75. ResultSetTableModel rst = new ResultSetTableModel("sun.jdbc.odbc.JdbcOdbcDriver",
  76. "jdbc:odbc:Driver=" +
  77. "{Microsoft Access Driver (*.mdb)}; DBQ=" + Hd, "", "",
  78. s);
  79. dados = new String[rst.getRowCount()][5];
  80. int aux = 0;
  81. while (rs.next()) {
  82. dados[aux][0] = rs.getString(1);
  83. dados[aux][1] = rs.getString(2);
  84. dados[aux][2] = rs.getString(3);
  85. dados[aux][3] = rs.getString(4);
  86. dados[aux][4] = rs.getString(5);
  87. aux++;
  88. }
  89. } catch (Exception ex) {
  90. Logger.getLogger(Controle.class.getName()).log(Level.SEVERE, null, ex);
  91. }
  92. return dados;
  93. }
  94.  
  95. ResultSet recuperaEstado(){
  96. String Hd = "C:\\Users\\Aluno\\Desktop\\banco.mdb";
  97. try {
  98. Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  99. Connection con= DriverManager.getConnection("jdbc:odbc:Driver=" +
  100. "{Microsoft Access Driver (*.mdb)};" +
  101. "DBQ=" + Hd ,"","");
  102. statement = con.createStatement();
  103. String s = null;
  104. s = "select * from estado_civil";
  105. rs = statement.executeQuery(s);
  106. }catch(Exception e){
  107. e.printStackTrace();
  108. }
  109. return rs;
  110. }
  111.  
  112.  
  113. public String[][] procurarFuncionario(String descricao,String funcao, String setor) {
  114. rs = null;
  115. String[][] dados = null;
  116. String Hd = "C:\\Users\\Aluno\\Desktop\\banco.mdb";
  117. try {
  118. Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  119. Connection con= DriverManager.getConnection("jdbc:odbc:Driver=" +
  120. "{Microsoft Access Driver (*.mdb)};" +
  121. "DBQ=" + Hd ,"","");
  122. statement = con.createStatement();
  123. String s = null;
  124. if(descricao !=null || !descricao.equals(""))
  125. s= "select p.codigo,p.nome,status,e.nome from funcionario p,funcao e, setor s where s.codigo = p.setor and p.funcao = e.codigo and p.nome like '%" + descricao + "%'";
  126. else
  127. s= "select p.codigo,p.nome,status,e.nome from funcionario p,funcao e where s.codigo = p.setor and p.funcao = e.codigo";
  128. s = s + " and funcao =" + new Integer(funcao).intValue();
  129. s = s + " and setor =" + new Integer(setor).intValue();
  130. rs = statement.executeQuery(s);
  131. ResultSetTableModel rst = new ResultSetTableModel("sun.jdbc.odbc.JdbcOdbcDriver",
  132. "jdbc:odbc:Driver=" +
  133. "{Microsoft Access Driver (*.mdb)}; DBQ=" + Hd, "", "",
  134. s);
  135. dados = new String[rst.getRowCount()][5];
  136. int aux = 0;
  137. while (rs.next()) {
  138. dados[aux][0] = rs.getString(1);
  139. dados[aux][1] = rs.getString(2);
  140. dados[aux][2] = rs.getString(3);
  141. dados[aux][3] = rs.getString(4);
  142. dados[aux][4] = rs.getString(5);
  143. aux++;
  144. }
  145. } catch (Exception ex) {
  146. Logger.getLogger(Controle.class.getName()).log(Level.SEVERE, null, ex);
  147. }
  148. return dados;
  149. }
  150.  
  151. ResultSet recuperaFuncao(){
  152. String Hd = "C:\\Users\\Aluno\\Desktop\\banco.mdb";
  153. try {
  154. Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  155. Connection con= DriverManager.getConnection("jdbc:odbc:Driver=" +
  156. "{Microsoft Access Driver (*.mdb)};" +
  157. "DBQ=" + Hd ,"","");
  158. statement = con.createStatement();
  159. String s = null;
  160. s = "select * from funcao";
  161. rs = statement.executeQuery(s);
  162. }catch(Exception e){
  163. e.printStackTrace();
  164. }
  165. return rs;
  166. }
  167.  
  168. ResultSet recuperaSetor(){
  169. String Hd = "C:\\Users\\Aluno\\Desktop\\banco.mdb";
  170. try {
  171. Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  172. Connection con= DriverManager.getConnection("jdbc:odbc:Driver=" +
  173. "{Microsoft Access Driver (*.mdb)};" +
  174. "DBQ=" + Hd ,"","");
  175. statement = con.createStatement();
  176. String s = null;
  177. s = "select * from setor";
  178. rs = statement.executeQuery(s);
  179. }catch(Exception e){
  180. e.printStackTrace();
  181. }
  182. return rs;
  183. }
  184.  
  185. void excluirRegistro(int z) {
  186. String Hd = "C:\\Users\\Aluno\\Desktop\\banco.mdb";
  187. try {
  188. Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  189. Connection con= DriverManager.getConnection("jdbc:odbc:Driver=" +
  190. "{Microsoft Access Driver (*.mdb)};" +
  191. "DBQ=" + Hd ,"","");
  192. statement = con.createStatement();
  193. String s = null;
  194. s = "delete from pessoa where codigo = " + z;
  195. statement.executeUpdate(s);
  196. JOptionPane.showMessageDialog(null, "Registro excluído com sucesso");
  197. }catch(Exception e){
  198. e.printStackTrace();
  199. }
  200. }
  201. }
Add Comment
Please, Sign In to add comment