Advertisement
Guest User

Untitled

a guest
Jan 30th, 2016
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. Markdown and HTML are turned off in code blocks:
  2. <i>This is not italic</i>, and [this is not a link](http://example.com)
  3.  
  4. void hddName(String ip) {
  5.  
  6. try {
  7. String commands="cmd /c wmic.exe DISKDRIVE get name";//HDD Details
  8. //System.out.println({"CMD", "/C", "WMIC OS GET Installdate,SerialNumber"});
  9. Process process = Runtime.getRuntime().exec(commands);
  10. process.getOutputStream().close(); //Closing output stream of the process
  11. System.out.println();
  12. StringBuilder sb=new StringBuilder();
  13. //Reading sucessful output of the command
  14. BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
  15. while ((s = reader.readLine()) != null)
  16. {
  17. sb.append(s).toString();//append output
  18. }
  19. System.out.println("result"+sb);//gives result with null keyword
  20. String ss=sb.toString();//gives result with null keyword
  21. System.out.println("result"+ss);
  22. try{
  23. System.out.println(s);
  24. Connection conn;
  25. Statement stmt;
  26. Class.forName("com.mysql.jdbc.Driver");
  27. conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/system","root","");
  28. stmt= conn.createStatement();
  29. String sql="update sys set hdname='"+ss+"' where ip='"+ip+"'";// save null to mysql database
  30. int val= stmt.executeUpdate(sql);
  31. conn.close();
  32. stmt.close();
  33. }
  34. catch(Exception e)
  35. {
  36.  
  37. }
  38. // Reading error if any
  39. reader = new BufferedReader(new InputStreamReader(process.getErrorStream()));
  40. while ((s = reader.readLine()) != null)
  41. {
  42. System.out.println(s);//any error
  43. }
  44. }
  45. catch (IOException e)
  46. {
  47. e.printStackTrace(); //TODO: necessary exception handling
  48. }
  49. // return s;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement