Advertisement
Guest User

Untitled

a guest
Jul 5th, 2017
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. package model;
  2.  
  3. import java.sql.*;
  4. import java.util.*;
  5.  
  6. public class DBTeacher {
  7.  
  8. public ArrayList<Teacher> searchTeachers(String school){
  9.  
  10.  
  11. try{
  12.  
  13. // Step1: Load JDBC Driver
  14. Class.forName("com.mysql.jdbc.Driver");
  15. // Step 2: Define Connection URL
  16. String connURL = "jdbc:mysql://localhost/dblect3?user=root&password=root";
  17. // Step 3: Establish connection to URL
  18. Connection conn = DriverManager.getConnection(connURL);
  19.  
  20. //String sql="Select * from teacher where school= '"+ school + "'";
  21. //Statement stmt=conn.createStatement();
  22.  
  23. //ResultSet rs=stmt.executeQuery(sql);
  24.  
  25. String sql="Select * from teacher where school=?";
  26. PreparedStatement pstmt=conn.prepareStatement(sql);
  27.  
  28. pstmt.setString(1, school);
  29. ResultSet rs=pstmt.executeQuery();
  30. //out.println("<table border='1'");
  31.  
  32. while(rs.next()){
  33.  
  34. String staffid=rs.getString("staffid");
  35. String name=rs.getString("name");
  36. String email=rs.getString("email");
  37. }
  38.  
  39.  
  40.  
  41. }catch (Exception e){
  42. System.out.println(e);
  43. return null;
  44. }
  45.  
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement