Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.*;
- public class viewcustomer{
- Connection connection;
- private void displaySQLErrors(SQLException e){
- System.out.println("SQLException: " + e.getMessage());
- System.out.println("SQLState: " + e.getSQLState());
- System.out.println("VendorError: " + e.getErrorCode());
- }
- public void connectToDB(){
- try{
- connection = DriverManager.getConnection("jdbc:mysql://localhost/javaday2?user=root&password=");
- } catch(SQLException e){
- displaySQLErrors(e);
- }
- }
- public void showAllCustomer(){
- try{
- Statement statement = connection.createStatement();
- ResultSet rs = statement.executeQuery("SELECT individual.FIRST_NAME, customer.ADDRESS, customer.CITY from customer INNER JOIN individual on customer.CUST_ID=individual.CUST_ID");
- System.out.println(" Customer View: ");
- System.out.println("===================");
- while(rs.next()){
- System.out.println("{First name="+rs.getString(1)+", Address="+rs.getString(2)+", City="+rs.getString(3)+"}");
- }
- rs.close();
- statement.close();
- // connection.close();
- } catch(SQLException e){
- displaySQLErrors(e);
- }
- }
- public static void main(String[] args){
- viewcustomer viewcustomer = new viewcustomer();
- viewcustomer.connectToDB();
- viewcustomer.showAllCustomer();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement