├── .idea ├── .gitignore ├── vcs.xml ├── modules.xml └── misc.xml ├── .gitignore ├── src ├── DatabaseConnection.java ├── InsertData.java └── Main.java └── untitled.iml /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ### IntelliJ IDEA ### 2 | out/ 3 | !**/src/main/**/out/ 4 | !**/src/test/**/out/ 5 | 6 | ### Eclipse ### 7 | .apt_generated 8 | .classpath 9 | .factorypath 10 | .project 11 | .settings 12 | .springBeans 13 | .sts4-cache 14 | bin/ 15 | !**/src/main/**/bin/ 16 | !**/src/test/**/bin/ 17 | 18 | ### NetBeans ### 19 | /nbproject/private/ 20 | /nbbuild/ 21 | /dist/ 22 | /nbdist/ 23 | /.nb-gradle/ 24 | 25 | ### VS Code ### 26 | .vscode/ 27 | 28 | ### Mac OS ### 29 | .DS_Store -------------------------------------------------------------------------------- /src/DatabaseConnection.java: -------------------------------------------------------------------------------- 1 | import java.sql.Connection; 2 | import java.sql.DriverManager; 3 | import java.sql.SQLException; 4 | 5 | public class DatabaseConnection { 6 | public static Connection getConnection() throws SQLException, ClassNotFoundException 7 | { 8 | Class.forName("com.mysql.cj.jdbc.Driver"); 9 | String url = "jdbc:mysql://localhost:3306/ecommerce"; 10 | String username = "root"; 11 | String password =""; 12 | 13 | return DriverManager.getConnection(url, username,password); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /untitled.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /src/InsertData.java: -------------------------------------------------------------------------------- 1 | import java.sql.Connection; 2 | import java.sql.SQLException; 3 | import java.sql.Statement; 4 | 5 | public class InsertData { 6 | public static void main(String[] args) { 7 | try 8 | { 9 | Connection con = DatabaseConnection.getConnection(); 10 | Statement stmt = con.createStatement(); 11 | System.out.println("Inserting records into the table"); 12 | String sql; 13 | sql = "INSERT INTO products VALUES(NULL,'Dew')"; 14 | stmt.executeUpdate(sql); 15 | sql = "INSERT INTO products VALUES(NULL,'Pepsi')"; 16 | stmt.executeUpdate(sql); 17 | sql = "INSERT INTO products VALUES(NULL,'Fanta')"; 18 | stmt.executeUpdate(sql); 19 | con.close(); 20 | } 21 | catch (Exception e) 22 | { 23 | System.out.println("aa"); 24 | e.printStackTrace(); 25 | } 26 | 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/Main.java: -------------------------------------------------------------------------------- 1 | import java.sql.Connection; 2 | import java.sql.ResultSet; 3 | import java.sql.ResultSetMetaData; 4 | import java.sql.Statement; 5 | 6 | // Press Shift twice to open the Search Everywhere dialog and type `show whitespaces`, 7 | // then press Enter. You can now see whitespace characters in your code. 8 | public class Main { 9 | public static void main(String[] args) { 10 | try 11 | { 12 | Connection con = DatabaseConnection.getConnection(); 13 | Statement stmt = con.createStatement(); 14 | ResultSet rs = stmt.executeQuery("select * from products"); 15 | ResultSetMetaData rsmd = rs.getMetaData(); 16 | System.out.println("hello"+rsmd.getColumnCount()); 17 | while(rs.next()) 18 | { 19 | System.out.println("ID: "+rs.getInt("id")+" Name: "+rs.getString("name")); 20 | } 21 | con.close(); 22 | } 23 | catch (Exception e) 24 | { 25 | System.out.println("aa"); 26 | e.printStackTrace(); 27 | } 28 | } 29 | } --------------------------------------------------------------------------------