JAva Swing/SQL Server 2000 sending messages in a LAN

Please support our Java advertiser: Programming Forums
Feb 10th, 2006
Views: 8,513
Thread Rating: 2 votes, 5.0000 average.
AddThis Social Bookmark Button
This prog uses SQL Server's Master Databases xp_cmdshell stored procedure (Shell Commands) to send messages in a LAN.Make Sure the driver name is 'netsend' and it points to Master Database. Check and change the username and passwords in the Java Program also.Make sure you have sufficient priviledges to execute stored procedures in SQL Server 2000.
java Syntax
  1. import java.awt.*;
  2. import java.awt.event.*;
  3. import javax.swing.*;
  4. import java.sql.*;
  5. import java.util.*;
  6.  
  7. public class NetSend extends JFrame implements ActionListener
  8. {
  9. JComboBox list = new JComboBox();
  10. JTextField message = new JTextField(20);
  11. JButton send = new JButton("Send");
  12. JTextField result = new JTextField(25);
  13.  
  14. private static Connection cn = null;
  15. private static Statement st= null;
  16. private ResultSet r= null;
  17.  
  18. public NetSend(String title){
  19. setTitle(title);
  20. initialise();
  21. Container c = getContentPane();
  22. c.setLayout(new FlowLayout(FlowLayout.CENTER));
  23. c.add(list);
  24. c.add(message);
  25. send.addActionListener(this);
  26. send.setMnemonic(KeyEvent.VK_S);
  27. c.add(send);
  28. result.setEditable(false);
  29. result.setBackground(Color.yellow);
  30. result.setForeground(Color.red);
  31. c.add(result);
  32. }
  33. public void actionPerformed(ActionEvent ae){
  34. if(ae.getSource()==send){
  35. String dest = String.valueOf(list.getSelectedItem());
  36. String msg = message.getText();
  37. try{
  38. Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  39. cn = DriverManager.getConnection("jdbc:odbc:netsend","mcp","mcp");
  40. st=cn.createStatement();
  41. ResultSet r=st.executeQuery("xp_cmdshell 'net send "+dest+" "+msg+"'");
  42. result.setText("Message Sent");
  43.  
  44. }catch(Exception e){result.setText("Error in Sending Message");}
  45. }
  46. }
  47. public void initialise(){
  48. try
  49. {
  50. Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  51.  
  52. cn = DriverManager.getConnection("jdbc:odbc:netsend","mcp","mcp");
  53. st=cn.createStatement();
  54. r=st.executeQuery("xp_cmdshell 'net view'");
  55.  
  56. String temp = new String();
  57. int i = 1;
  58. ArrayList machNames = new ArrayList();
  59. while(r.next())
  60. {
  61. machNames.add(r.getString("output"));
  62. }
  63. for(int x=3;x<machNames.size()-3;x++){
  64. temp = String.valueOf(machNames.get(x));
  65. list.addItem(temp.substring(2,temp.length()));
  66. }
  67. result.setText("Type your message and press ALT and S");
  68. }
  69. catch(Exception e){result.setText("Not able to retrieve the hosts");}
  70. }
  71. public static void main(String args[])
  72. {
  73. NetSend ns = new NetSend("Send your messages to PC's in LAN");
  74. ns.setVisible(true);
  75. ns.setSize(400,400);
  76. }
  77. }

Only community members can submit or comment on code snippets. You must register or log in to contribute.

Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 10:31 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC