Advertisement
Guest User

Untitled

a guest
Sep 26th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. package dal;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.PreparedStatement;
  6. import java.sql.ResultSet;
  7. import java.sql.SQLException;
  8.  
  9. public class DbCronus {
  10.  
  11. static Connection con = null;
  12. static PreparedStatement preState= null;
  13. static ResultSet rs = null;
  14.  
  15. public static Connection getConn() throws SQLException {
  16. String connStr = "jdbc:sqlserver://172.16.198.129:1433;databaseName=Uppgift2;user=sa;password=mats;";
  17.  
  18. return DriverManager.getConnection(connStr);
  19.  
  20. }
  21. public static String getKeys(){
  22. return "SELECT TABLE_NAME, COLUMN_NAME FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE";
  23. }
  24. public static String getIndex(){
  25. return "SELECT * FROM sys.indexes";
  26. }
  27. public static String getTableCons() {
  28. return "SELECT * FROM INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE";
  29. }
  30. public static String getAllTablesOne(){
  31. return "SELECT * FROM INFORMATION_SCHEMA.TABLES";
  32. }
  33. public static String getAllTablesTwo(){
  34. return "SELECT sobjects.name FROM sysobjects sobjects WHERE sobjects.xtype = 'U'";
  35. }
  36. public static String getEmployeeOne(){
  37. return "SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'CRONUS Sverige AB$Employee'";
  38. }
  39. public static String getEmployeeTwo(){
  40. return "SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'CRONUS Sverige AB$Employee'";
  41.  
  42. }
  43. public static String getTableMaxRows(){
  44. return "SELECT TOP 1 t.name AS TableName, SUM(p.rows) AS RowCounts FROM sys.tables t INNER JOIN sys.indexes i ON t.object_id = i.object_id INNER JOIN sys.partitions p ON i.object_id = p.object_id AND i.index_id = p.index_id GROUP BY t.name, i.object_id, i.index_id, i.name ORDER BY SUM(p.rows) desc";
  45. }
  46. public static String getMetaData(String from){
  47. return "SELECT * FROM "+from+" ";
  48.  
  49. }public static String getColumnNames(){
  50.  
  51. return "SELECT top 5 INFORMATION_SCHEMA.COLUMNS.COLUMN_NAME from INFORMATION_SCHEMA.COLUMNS where TABLE_NAME = ? ";
  52.  
  53. }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement