SHARE
TWEET

Untitled

a guest Sep 11th, 2019 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package testjdbc;
  2.  
  3.  
  4. import java.sql.Connection;
  5. import java.sql.DriverManager;
  6. import java.sql.PreparedStatement;
  7. import java.sql.ResultSet;
  8. import java.sql.SQLException;
  9.  
  10. public class sql_con {
  11.  
  12.      
  13.     public static void main(String[] args) {
  14.          
  15.     String url = "jdbc:sqlserver://localhost:1433;databaseName=AbsentNotev2";
  16.     String user = "sa";
  17.     String pass = "123456";
  18.  
  19. String query="select s.S_ID,s.SName,s.SPW,s.SMobileNumber,s.SEmail,scj.StartNumber,c.CName from Student s \n" +
  20. "join StudentClassJoin scj \n" +
  21. "on s.S_ID = scj.S_ID\n" +
  22. "join StartClass sc\n" +
  23. "on scj.StartNumber = sc.StartNumber\n" +
  24. "join class c\n" +
  25. "on sc.CNumber =c.CNumber\n" +
  26. "where s.S_ID = 'A123456789'" ;
  27.         ResultSet rs =null;
  28.          try (
  29.                 Connection con = DriverManager.getConnection(url,user,pass);
  30.             PreparedStatement ps =con.prepareStatement(query);
  31.                 )
  32.          {
  33.          rs =ps.executeQuery();
  34.              while(rs.next()){    
  35.               String name , cname, snumber,sid;
  36.               name = rs.getString(1);
  37.               cname=rs.getString(2);
  38.               snumber=rs.getString(3);
  39.               sid=rs.getString(4);
  40.                  System.out.println(name +"  "+cname+"  "+snumber+"  "+sid);
  41.                  }
  42.          }
  43.      
  44.      
  45.      catch (SQLException e) {
  46.             System.err.println(e);
  47.         }
  48.          }
  49.    
  50. }
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