Advertisement
Guest User

Untitled

a guest
Feb 20th, 2019
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.68 KB | None | 0 0
  1. try {
  2. Class.forName("com.mysql.cj.jdbc.Driver");
  3. connect = DriverManager.getConnection("jdbc:mysql://" + host + "/users?" + "user=" + user + "&password=" + pw );
  4. statement = connect.createStatement();
  5. resultSet = statement.executeQuery("select * from account");
  6. writeResultSet(resultSet);
  7. } catch (Exception e) {
  8. throw e;
  9. } finally {
  10. close();
  11. }
  12.  
  13. Class.forName("com.mysql.cj.jdbc.Driver");
  14. connect = DriverManager.getConnection("jdbc:mysql://" + host + "/users?" + "user=" + user + "&password=" + pw );
  15. preparedStatement = connect.prepareStatement("insert into account values (default, ?, ?)");
  16.  
  17. int dbAmount = 0;
  18. statement = connect.createStatement();
  19. resultSet = statement.executeQuery("select * from account");
  20. while (resultSet.next()) {
  21. dbAmount = resultSet.getInt("balance");
  22. }
  23.  
  24. dbAmount += amount;
  25.  
  26. preparedStatement.setInt(1, dbAmount);
  27. preparedStatement.setString(2, updatedAt);
  28. preparedStatement.executeUpdate();
  29. } catch (Exception e) {
  30. throw e;
  31. } finally {
  32. close();
  33. }
  34.  
  35. Class.forName("com.mysql.cj.jdbc.Driver");
  36. connect = DriverManager.getConnection("jdbc:mysql://" + host + "/users?" + "user=" + user + "&password=" + pw );
  37. preparedStatement = connect.prepareStatement("update account set balance = ?, updatedAt = ? where id = 1");
  38.  
  39. int dbAmount = 0;
  40. statement = connect.createStatement();
  41. resultSet = statement.executeQuery("select * from account");
  42. while (resultSet.next()) {
  43. dbAmount = resultSet.getInt("balance");
  44. }
  45.  
  46. dbAmount += amount;
  47.  
  48. preparedStatement.setInt(1, dbAmount);
  49. preparedStatement.setString(2, updatedAt);
  50. preparedStatement.setInt(3, 1);
  51. preparedStatement.executeUpdate();
  52. } catch (Exception e) {
  53. throw e;
  54. } finally {
  55. close();
  56. }
  57.  
  58. java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost/users?user=********&password=********
  59. at java.sql.DriverManager.getConnection(Unknown Source)
  60. at java.sql.DriverManager.getConnection(Unknown Source)
  61. at com.nsoft.serviceb.DbConnection.writeDataBase(DbConnection.java:39)
  62. at com.nsoft.serviceb.ServiceB.insertInDb(ServiceB.java:73)
  63. at com.nsoft.serviceb.ServiceB.lambda$receiveData$0(ServiceB.java:55)
  64. at com.rabbitmq.client.impl.recovery.AutorecoveringChannel$2.handleDelivery(AutorecoveringChannel.java:577)
  65. at com.rabbitmq.client.impl.ConsumerDispatcher$5.run(ConsumerDispatcher.java:149)
  66. at com.rabbitmq.client.impl.ConsumerWorkService$WorkPoolRunnable.run(ConsumerWorkService.java:104)
  67. at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
  68. at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement