Guest User

Untitled

a guest
Jan 15th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. try{
  2. String url = "jdbc:mysql://localhost/qrdb";
  3. String username = "root";
  4. String password = "****";
  5. Class.forName("com.mysql.cj.jdbc.Driver").getDeclaredConstructor().newInstance();
  6.  
  7. String sqlCommand = "CREATE TABLE items (Id INT PRIMARY KEY AUTO_INCREMENT, name VARCHAR(20), price INT)";
  8.  
  9. try (Connection conn = DriverManager.getConnection(url, username, password)){
  10.  
  11. Statement statement = conn.createStatement();
  12.  
  13. statement.executeUpdate(sqlCommand);
  14.  
  15. Log.i("mytag","Database has been created!");
  16. }
  17. }
  18. catch(Exception ex){
  19. Log.i("mytag","Connection failed...");
  20.  
  21. Log.i("mytag", "" + ex);
  22. }
Add Comment
Please, Sign In to add comment