Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- try{
- String url = "jdbc:mysql://localhost/qrdb";
- String username = "root";
- String password = "****";
- Class.forName("com.mysql.cj.jdbc.Driver").getDeclaredConstructor().newInstance();
- String sqlCommand = "CREATE TABLE items (Id INT PRIMARY KEY AUTO_INCREMENT, name VARCHAR(20), price INT)";
- try (Connection conn = DriverManager.getConnection(url, username, password)){
- Statement statement = conn.createStatement();
- statement.executeUpdate(sqlCommand);
- Log.i("mytag","Database has been created!");
- }
- }
- catch(Exception ex){
- Log.i("mytag","Connection failed...");
- Log.i("mytag", "" + ex);
- }
Add Comment
Please, Sign In to add comment