944,171 Members | Top Members by Rank

Ad:
  • Java Code Snippet
  • Views: 11080
  • Java RSS
0

JAva Swing/SQL Server 2000 sending messages in a LAN

by on Feb 10th, 2006
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 Code Snippet (Toggle Plain Text)
  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. }
Comments on this Code Snippet
Aug 15th, 2009
0

Re: JAva Swing/SQL Server 2000 sending messages in a LAN

I have a doubt in database connectivity. Could you please tell me how it's work and what does it mean netsend driver.
Newbie Poster
Antony Prabu is offline Offline
1 posts
since Aug 2009
Message:
Previous Thread in Java Forum Timeline: random generation of both characters and numbers together, i.e example: fghg6pl89m
Next Thread in Java Forum Timeline: Help my Circular Linked List





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC