Advertisement
Guest User

Untitled

a guest
Apr 2nd, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. package Connectivity;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.Statement;
  6.  
  7. public class BaseConnection {
  8. private Connection connection;
  9.  
  10. public BaseConnection() {
  11. getConnection();
  12. }
  13.  
  14. public Connection getConnection() {
  15. String dbname = "ExpensesApp";
  16. String username= "root";
  17. String password= "";
  18. try {
  19. Class.forName("com.mysql.jdbc.Driver");
  20. connection = DriverManager.getConnection("jdbc:mysql://localhost:8080/"+dbname+username);
  21. }
  22. catch(Exception e) {
  23. e.printStackTrace();
  24. }
  25. return connection;
  26. }
  27.  
  28. public void addToBase(String date, String category, String price, String description){
  29. try{
  30. Statement statement = connection.createStatement();
  31. String sql = "INSERT INTO EXPENSESBOARD VALUES('"+date+","+category+","+price+","+description+"')";
  32. statement.executeUpdate(sql);
  33. }
  34. catch (Exception e) {
  35. e.printStackTrace();
  36. }
  37.  
  38. }
  39.  
  40.  
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement