Guest User

Untitled

a guest
Nov 7th, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. public Application(String id, String appName,String appDetail)
  2. {
  3. this.id = id;
  4. this.appName = appName;
  5. this.appDetail = appDetail;
  6.  
  7. }
  8.  
  9. Connection conn = null;
  10. String dbName = "TestDTM";
  11. String serverip="21.13.52.199";
  12. String serverport="23456";
  13. String url = "jdbc:sqlserver://"+serverip+"\SQLEXPRESS:"+serverport+";databaseName="+dbName+"";
  14. Statement stmt = null;
  15. ResultSet result = null;
  16. String driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
  17. String databaseUserName = "rowReps";
  18. String databasePassword = "ashter%$mass";
  19.  
  20. //Creating map of Books
  21. Map<Integer,Application> map=new HashMap<Integer,Application>();
  22.  
  23. try
  24. {
  25. //Class.forName(driver).newInstance();
  26. conn = DriverManager.getConnection(url, databaseUserName, databasePassword);
  27. stmt = conn.createStatement();
  28. result = null;
  29. String appId = "";
  30. String appName = "";
  31. String appDetail="";
  32.  
  33. result = stmt.executeQuery("select * from language ");
  34. int count = 1;
  35. String appObj="";
  36. // Application appObj = new Application("test","test");
  37.  
  38. while (result.next())
  39. {
  40.  
  41. appId = result.getString(1);
  42. appName = result.getString(2);
  43. appDetail = result.getString(3);
  44.  
  45.  
  46. Application appObj1 = new Application(appId,appName,appDetail);
  47. map.put(count,appObj1);
  48. count++;
  49.  
  50.  
  51.  
  52.  
  53. }
  54.  
  55. conn.close();
  56.  
  57.  
  58. for(Map.Entry<Integer, Application> entry:map.entrySet())
  59. {
  60. int key=entry.getKey();
  61. Application applicationMap=entry.getValue();
  62. System.out.println(key + " : " + applicationMap.appName + " : " + applicationMap.appDetail);
  63.  
  64. }
  65.  
  66.  
  67.  
  68. }
  69. catch (Exception e)
  70. {
  71. e.printStackTrace();
  72. }
Add Comment
Please, Sign In to add comment