Advertisement
Guest User

Untitled

a guest
Mar 6th, 2017
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. public static String Server="192.168.0.26:1433";
  2. public static String DataBase="TEST_CON";
  3. public static String Username="sa";
  4. public static String Password="12345678";
  5.  
  6. public static Connection Abrir() throws ClassNotFoundException, SQLException, InstantiationException, IllegalAccessException
  7. {
  8. Class.forName("net.sourceforge.jtds.jdbc.Driver").newInstance();
  9. Connection conn = DriverManager.getConnection("jdbc:sqlserver://"+conexao.Server+ ";databaseName="+conexao.DataBase,conexao.Username,conexao.Password);
  10. return conn;
  11. }
  12.  
  13. public int Testar() throws ClassNotFoundException, SQLException, InstantiationException, IllegalAccessException {
  14. int u = 0;
  15. Connection conn = conexao.Abrir();
  16. Statement MW = conn.createStatement();
  17. ResultSet rs = MW.executeQuery("SELECT*From Tb_utilizador order by Nome");
  18.  
  19. while (rs.next()) {
  20. u = 1;
  21. }
  22. return u;
  23. }
  24.  
  25. try {
  26. b.Testar();
  27. }
  28. catch (ClassNotFoundException e)
  29. {
  30. Mensagem("Erro1",""+e.getMessage());
  31. }
  32. catch (InstantiationException e)
  33. {
  34. Mensagem("Erro2",""+e.getMessage());
  35. }
  36. catch (IllegalAccessException e)
  37. {
  38. Mensagem("Erro3",""+e.getMessage());
  39. }
  40. catch (SQLException e)
  41. {
  42. Mensagem("Erro4",""+e.getMessage());
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement