From the above video you can understand how to write java code to select rows from table using SQL Select statement.
Steps to Write Code.
1. The very first step is to Load the JDBC-MySQL Driver.
The above java code will load the driver using try-catch statement, because the Class.forName() method will throw class not found Exception.
2. Second Step is to Establish the Connection
Connection conn = DriverManager.getConnection(“jdbc:mysql://localhost/simpledb”, “root”, “123”);
The above java code will establish the connection to the database “simpledb” using its user: root and password: 123
3. Third step is to create an SQL statement and pass to “simpledb”
String sql = “select * from emp”;
Statement stmt = conn.createStatement();
ResultSet res = stmt.executeQuery(sql);
The above code snippet will pass SQL statement to the database and obtain rows of “emp” table. The rows obtained will be stored in the ResultSet object.
4. Fourth step is to query the ResultSet object. and to print output.
#java, #mysql, #database, #projects, #javaprojects