Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.*;
- // for this, we are using tbl_products2
- public class Day24A {
- public static void main(String[] args) {
- getAllRows();
- }
- public static void getAllRows() {
- String address = "jdbc:mysql://localhost:3306/db_mr_b5";
- String userName = "root";
- String passWord = "";
- String sqlQuery = "SELECT * FROM tbl_products2";
- try {
- Connection conn = DriverManager.getConnection(
- address,userName,passWord);
- PreparedStatement stmt = conn.prepareStatement(sqlQuery);
- ResultSet rs = stmt.executeQuery();
- while (rs.next()) {
- System.out.print(rs.getString(1)+" | ");
- System.out.print(rs.getString(2)+" | ");
- System.out.print(rs.getString(3)+" | ");
- System.out.print(rs.getString(4)+" | ");
- System.out.print(rs.getString(5)+" | ");
- System.out.print(rs.getString(6)+" | ");
- System.out.println();
- }
- conn.close();
- } catch (Exception e) {
- System.out.println(e.getMessage());
- }
- System.out.println("getallrows()");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment