Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.88 KB | None | 0 0
  1. import java.sql.Connection;
  2. import java.sql.DriverManager;
  3. import java.sql.ResultSet;
  4. import java.sql.Statement;
  5.  
  6. public class Driver {
  7.  
  8.     public static void main(String[] args) {
  9.        
  10.         try{
  11.             // Get a connection to the database
  12.             Connection myConn = DriverManager.getConnection("jdbc:mysql://localhost:3306/public_laundry1", "root", "alonso");
  13.        
  14.             // Create a statement
  15.             Statement myStmt= myConn.createStatement();
  16.            
  17.             // Execute SQL query
  18.             ResultSet myRs = myStmt.executeQuery("SELECT `customers`.`name`, `orders`.`order_id`FROM `customers` JOIN `orders` ON(customers.id= orders.customer_id) where customers.promocode=25253");
  19.        
  20.             // Process the result set
  21.             while(myRs.next()){
  22.                 System.out.println("Promo user: " + myRs.getString("name") + " with order id: " + myRs.getInt("order_id"));
  23.             }
  24.         }catch(Exception e){
  25.             e.printStackTrace();
  26.         }
  27.  
  28.     }
  29.  
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement