Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public Application(String id, String appName,String appDetail)
- {
- this.id = id;
- this.appName = appName;
- this.appDetail = appDetail;
- }
- Connection conn = null;
- String dbName = "TestDTM";
- String serverip="21.13.52.199";
- String serverport="23456";
- String url = "jdbc:sqlserver://"+serverip+"\SQLEXPRESS:"+serverport+";databaseName="+dbName+"";
- Statement stmt = null;
- ResultSet result = null;
- String driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
- String databaseUserName = "rowReps";
- String databasePassword = "ashter%$mass";
- //Creating map of Books
- Map<Integer,Application> map=new HashMap<Integer,Application>();
- try
- {
- //Class.forName(driver).newInstance();
- conn = DriverManager.getConnection(url, databaseUserName, databasePassword);
- stmt = conn.createStatement();
- result = null;
- String appId = "";
- String appName = "";
- String appDetail="";
- result = stmt.executeQuery("select * from language ");
- int count = 1;
- String appObj="";
- // Application appObj = new Application("test","test");
- while (result.next())
- {
- appId = result.getString(1);
- appName = result.getString(2);
- appDetail = result.getString(3);
- Application appObj1 = new Application(appId,appName,appDetail);
- map.put(count,appObj1);
- count++;
- }
- conn.close();
- for(Map.Entry<Integer, Application> entry:map.entrySet())
- {
- int key=entry.getKey();
- Application applicationMap=entry.getValue();
- System.out.println(key + " : " + applicationMap.appName + " : " + applicationMap.appDetail);
- }
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
Add Comment
Please, Sign In to add comment