Thu. Oct 31st, 2019

Host your Website

Read and learn

FatCow Plan for $3.15/mo. only

Java Projects with Source Code JDBC Tutorials – 5 – Java Program to "Select Rows from Table"

1 min read



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.

try {
Class.forName(“com.mysql.jdbc.Driver”);
}catch(Exception e){

}
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

try{
Connection conn = DriverManager.getConnection(“jdbc:mysql://localhost/simpledb”, “root”, “123”);
}catch(Exception e){
}

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”

try{
String sql = “select * from emp”;
Statement stmt = conn.createStatement();
ResultSet res = stmt.executeQuery(sql);
}catch(Exception e){

}
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

1 thought on “Java Projects with Source Code JDBC Tutorials – 5 – Java Program to "Select Rows from Table"

Comments are closed.

Copyright © All rights reserved. | Newsphere by AF themes.