Advertisement
Guest User

Untitled

a guest
May 7th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package dbtest;
  7.  
  8. import java.sql.*;
  9. /**
  10. *
  11. * @author User
  12. */
  13. public class DbTest {
  14.  
  15. public static void main(String[] args) throws SQLException
  16. {
  17. Connection myConn = null;
  18. Statement myStmt = null;
  19. ResultSet myRs = null;
  20.  
  21. String uname = "root";
  22. String pass = "hej";
  23.  
  24. try
  25. {
  26. myConn = DriverManager.getConnection("jdbc:mysql://localhost:3306/library?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC", uname, pass);
  27.  
  28. myStmt = myConn.createStatement();
  29.  
  30. myRs = myStmt.executeQuery("select * FROM skadespelare");
  31.  
  32. while (myRs.next())
  33. {
  34. System.out.println(myRs.getString("fNamn") + ", " + myRs.getString("eNamn"));
  35. }
  36. }catch(Exception exc)
  37. {
  38. exc.printStackTrace();
  39. }finally
  40. {
  41. if(myRs != null)
  42. {
  43. myRs.close();
  44. }
  45. if(myStmt != null)
  46. {
  47. myStmt.close();
  48. }
  49. if(myConn != null)
  50. {
  51. myConn.close();
  52. }
  53. }
  54. }
  55.  
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement