daily pastebin goal
58%
SHARE
TWEET

Untitled

a guest Mar 17th, 2018 87 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package MySQLConnection;
  2.  
  3. import java.sql.*;
  4. import java.util.Scanner;
  5. import static java.lang.System.out;
  6.  
  7. public class UserInput {
  8.     public static void main(String[] args) {
  9.         Scanner myScanner = new Scanner(System.in);
  10.         out.println("Enter Department #:");
  11.         int uDeptno = myScanner.nextInt();
  12.         out.println(uDeptno);
  13.  
  14.         try {
  15.             Connection myConn = DriverManager.getConnection("jdbc:mysql://localhost:3306/uml","root","Greenmonster12");
  16.  
  17.             //create type of statement (statement,prepared statement, callable statement)
  18.             Statement myStmt = myConn.createStatement();
  19.  
  20.             ResultSet myRS = myStmt.executeQuery("{call user_show_dept(uDeptno)}");
  21.  
  22.             while (myRS.next()) {
  23.                 out.println(myRS.getString("deptno"+" - "));
  24.                 out.println(myRS.getString("dname"+" - "));
  25.                 out.println(myRS.getString("loc"+"."));
  26.             }
  27.  
  28.  
  29.  
  30.         } catch (SQLException e) {
  31.             e.printStackTrace();
  32.  
  33.         }
  34.     }
  35. }
  36.    
  37. DELIMITER $$
  38.  
  39. USE `uml`$$
  40.  
  41. DROP PROCEDURE IF EXISTS `user_show_dept`$$
  42. CREATE DEFINER = `tpenney`@`%` PROCEDURE `user_show_dept`(uDeptno INT(2))
  43.  
  44.     BEGIN
  45.         SELECT *
  46.         FROM dept
  47.         WHERE deptno=uDeptno;
  48.     END$$
  49.  
  50. DELIMITER ;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top