Guest User

_DIS_BANK

a guest
Oct 29th, 2017
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. package eksemepel;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.ResultSet;
  6. import java.sql.SQLException;
  7. import java.sql.Statement;
  8.  
  9. public class SkriveTilFil {
  10.  
  11. public static Connection getConnection() throws SQLException {
  12. return DriverManager.getConnection("jdbc:sqlserver://Dennis\\DENNIS;databaseName=Banksystem;user=sa;password=helloWorld;");
  13. }
  14.  
  15. public static Statement getStatement() throws SQLException {
  16. return SkriveTilFil.getConnection().createStatement();
  17. }
  18.  
  19.  
  20. public static String getFraKonto(int kontoNr) throws SQLException {
  21. boolean findes = false;
  22. String gemString = null;
  23.  
  24. ResultSet res = SkriveTilFil.getStatement().executeQuery("Select Saldo from Konto where Konto.ktoNr = " + kontoNr);
  25.  
  26. gemString = res.getString(1);
  27.  
  28. if (gemString == null){
  29. System.out.println("intet at komme efter");
  30. } else {
  31. System.out.println("Der er data");
  32. }
  33. return gemString;
  34. }
  35.  
  36. public static String getTilKonto(int kontoNr) throws SQLException {
  37. boolean findes = false;
  38. String gemString = null;
  39.  
  40. ResultSet res = SkriveTilFil.getStatement().executeQuery("Select Saldo from Konto where Konto.ktoNr = " + kontoNr);
  41.  
  42. gemString = res.getString(1);
  43.  
  44. if (gemString == null){
  45. System.out.println("intet at komme efter");
  46. } else {
  47. System.out.println("Der er data");
  48. }
  49. return gemString;
  50. }
  51.  
  52.  
  53. public static void main(String[] args) throws SQLException {
  54.  
  55. SkriveTilFil.getTilKonto(1234567);
  56.  
  57.  
  58. }
  59. }
Add Comment
Please, Sign In to add comment