SHARE
TWEET

Untitled

a guest Sep 11th, 2019 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package testjdbc;
  2.  
  3.  
  4. import java.sql.Statement;
  5. import java.sql.Connection;
  6. import java.sql.DriverManager;
  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.         Connection conn = null;
  16.     String url = "jdbc:sqlserver://localhost:1433;databaseName=AbsentNotev2";
  17.     String user = "sa";
  18.     String pass = "123456";
  19.  
  20. String query="select s.S_ID,s.SName,s.SPW,s.SMobileNumber,s.SEmail,scj.StartNumber,c.CName from Student s \n" +
  21. "join StudentClassJoin scj \n" +
  22. "on s.S_ID = scj.S_ID\n" +
  23. "join StartClass sc\n" +
  24. "on scj.StartNumber = sc.StartNumber\n" +
  25. "join class c\n" +
  26. "on sc.CNumber =c.CNumber\n" +
  27. "where s.S_ID = 'A123456789'" ;
  28.  
  29.          try {
  30.                  Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
  31.                 conn = DriverManager.getConnection(url,user,pass);
  32.          if (conn != null && !conn.isClosed())
  33.          {
  34.           Statement stmt = conn.createStatement();
  35.           ResultSet rs = stmt.executeQuery(query);
  36.           while(rs.next()){    
  37.             String name , cname, snumber,sid;
  38.             name = rs.getString(1);
  39.             cname=rs.getString(2);
  40.             snumber=rs.getString(3);
  41.             sid=rs.getString(4);
  42.                System.out.println(name +"  "+cname+"  "+snumber+"  "+sid);
  43.                }
  44.          }
  45.          } catch (ClassNotFoundException e) {
  46.              e.printStackTrace();
  47.          } catch (SQLException e) {
  48.              e.printStackTrace();
  49.          }
  50.          }
  51.     }
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
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top