Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 8 of 8

Thread: sms coding in java

  1. #1
    Junior Member
    Join Date
    Apr 2013
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default sms coding in java

    i want java program for sending sms alert to user of my website


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: sms coding in java

    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Apr 2013
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: sms coding in java

    i want java program for sending sms alert to user of my website



    thanks in advance

    --- Update ---

    import java.io.*;
    import java.util.*;
    import java.util.concurrent.SynchronousQueue;
    import java.util.concurrent.LinkedBlockingQueue;
    import java.util.concurrent.TimeUnit;
    import java.net.*;
    //import com.joomfire.sms.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.sql.*;

    public class SMSGateway implements SmsListenerInterface

    {
    private static java.util.ResourceBundle res;
    private static final String db_name = "test";
    static SmsTerminal term = null;
    private Connection con = null; //for database connection
    private Statement stmt;
    private ResultSet rs;
    private String msgStatus = "";
    private String check = "";
    SynchronousQueue<OutMessage> smsQueue = new SynchronousQueue<OutMessage>();

    public static void main(String[] args)
    {
    new SMSGateway();
    }

    public SMSGateway()
    {
    String str;

    try
    {
    Class.forName("com.mysql.jdbc.Driver").newInstance ();
    }
    catch (Exception e)
    {
    System.out.println("Exception in init(): Unable to load JDBC driver");
    }

    try
    {

    con = DriverManager.getConnection("jdbc:mysql://localhost:06/winnova", "root", " root");
    System.out.println("conn: "+con);
    }
    catch (Exception e)
    {
    System.out.println("Exception in init(): Unable to establish connection to database '" + db_name + "'");
    }

    try
    {
    res = Utils.getResources();
    }
    catch (java.util.MissingResourceException mre)
    {
    mre.getMessage();
    System.exit(1);
    }

    str = res.getString("samplesmsapp.SampleSmsApp_starting" );
    System.out.println(str);

    String confFileName = "samplesmsapp.conf";
    Properties conf = null;
    FileInputStream confIn = null;

    try
    {
    File confFile = new File(confFileName);
    confIn = new FileInputStream(confFile);
    conf = new Properties();
    conf.load(confIn);
    }
    catch (IOException e)
    {
    System.err.println(res.getString("samplesmsapp.cou ld_not_read_") + confFileName + ": " + e);
    System.exit(1);
    }
    finally
    {
    try
    {
    if(confIn!=null)
    confIn.close();
    }
    catch (IOException e) { ; }
    }
    System.out.println(res.getString("samplesmsapp.-_configuration_read"));

    // get configuration parameter values.
    String smsTerminalPort = conf.getProperty("smsTerminalPort");
    int smsTerminalBitRate = Integer.parseInt(conf.getProperty("smsTerminalBitR ate"));
    boolean includeSmscInfoLen = new Boolean(conf.getProperty("includeSmscInfoLen")).bo oleanValue();
    String smscAddress = conf.getProperty("smscAddress");

    System.err.println(res.getString("samplesmsapp.-_connecting_to_SMS_terminal._please_wait."));

    try
    {
    term = new SmsTerminal(smsTerminalPort, smsTerminalBitRate, this);
    term.initialize();
    if(includeSmscInfoLen)
    {
    term.setMsgOutIncludeSmscAddrLen(includeSmscInfoLe n);
    if(smscAddress != null)
    term.setMsgOutSmscAddr(smscAddress);
    }
    }
    catch (Exception e)
    {
    str=res.getString("samplesmsapp.unable_to_create_a _SmsTerminal");
    System.err.println(str);
    System.err.println(res.getString("samplesmsapp.msg :_") + e);
    System.exit(1);
    }

    //Create new smsQueue thread here
    SMSQueueThread smsQueueThread = new SMSQueueThread("SMS Queue Thread", smsQueue, System.out);
    smsQueueThread.start();

    str = res.getString("samplesmsapp.-_connected_to_terminal");
    System.out.println(str);

    try
    {
    ServerSocket ss = new ServerSocket(4444);
    System.out.println("Server started... waiting for Client...");

    while(true)
    {
    Socket connectToClient = ss.accept();
    HandleAClient thread = new HandleAClient(connectToClient);
    thread.start();
    }
    }
    catch(IOException ex)
    {
    System.err.println(ex);
    }
    }

    public void receiveSms(int statusCode, String errmsg, SmsMsgIncoming msg)

    {

    if(statusCode == SmsTerminal.SC_OK)
    {
    System.out.println(res.getString("samplesmsapp.msg _received:_") + msg.toString());


    // Recieved SMS & HP
    String rAdm = msg.getMessage();
    String rNum = msg.getSenderNumber();

    System.out.println("Recieve Message : " + rAdm);
    System.out.println("Recieve Number : " + rNum);

    // INSERT SMS & HP INTO DATABASE
    try {

    String xxx;
    xxx="";
    System.out.println("+65 ooo : " + xxx);
    stmt = con.createStatement();
    //stmt.executeUpdate("INSERT INTO records(sms_id,admission_no,mobile_no,status,datet ime) VALUES(null,'"+rAdm+"','"+rNum.substring(3, rNum.length())+"','in', now())");


    }
    catch (Exception e)
    {
    System.out.println("Exception in mySQL(): " + e.getMessage() );
    }
    }
    else
    {
    System.err.println(res.getString("samplesmsapp.err or_receiving_SMS_message:_") + errmsg);
    }
    }

    public void destroy()
    {
    try {
    if (con != null)
    con.close();
    }
    catch (SQLException excIgnored){}
    } // End destroy()


    class HandleAClient extends Thread
    {
    private Socket connectToClient;

    public HandleAClient(Socket socket)
    {
    this.connectToClient = socket;
    }

    public void run()
    {

    synchronized(connectToClient)
    {
    try
    {
    BufferedReader fromClient = new BufferedReader(new InputStreamReader(connectToClient.getInputStream() ));
    PrintWriter toClient = new PrintWriter(connectToClient.getOutputStream(), true);

    String selection, outputLine;
    while ((selection = fromClient.readLine()) != null)
    {
    String msg = "";
    String num = "";

    if(selection.equals("phone"))
    {
    // RECIEVE NUMBERS AND MSG FROM SERVLET
    num = fromClient.readLine();
    msg = fromClient.readLine();

    System.out.println("Phone = " + num);
    System.out.println("Message = " + msg);

    try {
    smsQueue.offer(new OutMessage(num, msg),10,TimeUnit.SECONDS);
    }
    catch (InterruptedException ie)
    {
    ie.printStackTrace();
    }

    // SendSMS sms = new SendSMS(num, msg);
    // sms.start();
    }
    else
    {
    // RECIEVE GROUP AND MSG FROM SERVLET
    String group = fromClient.readLine();
    msg = fromClient.readLine();

    System.out.println("Group : "+group);

    try
    {
    stmt = con.createStatement();
    // rs = stmt.executeQuery("SELECT mobile_no FROM student WHERE course = '"+group+"'");

    while(rs.next())
    {
    num = num + rs.getString(1) + ",";
    }

    System.out.println("Numbers = " + num);

    smsQueue.offer(new OutMessage(num, msg),10,TimeUnit.SECONDS);

    // SendSMS sms = new SendSMS(num, msg);
    // sms.start();
    }
    catch (Exception e) {
    e.printStackTrace();
    }
    }
    }
    }
    catch(IOException ex)
    {
    System.err.println(ex);
    }
    }
    }
    }

    class SendSMS extends Thread
    {
    private String num;
    private String msg;

    public SendSMS(String numbers, String message)
    {
    num = numbers;
    msg = message;
    System.out.println("Message = " + message);
    }

    public void run()
    {
    // BREAKING NUMBERS INTO TOKENS
    StringTokenizer st = new StringTokenizer(num,",");

    while (st.hasMoreTokens())
    {

    String sendNum_65 =st.nextToken().trim();
    String sendNum = "65" + sendNum_65;
    System.out.println("Phone = " + sendNum);

    // SEND INDIVIDUAL TOKENS
    try
    {
    System.err.println(res.getString("samplesmsapp.msg :_'") + sendNum + "', '" + msg + "'");
    term.sendMessage(sendNum, msg);

    try
    {
    stmt = con.createStatement();
    //stmt.executeUpdate("INSERT INTO smsrecords(admission_no,mobile_no,status,datetime) VALUES('"+sendNum_65+"','"+msg+"', now(), 'out')");

    }
    catch (Exception e)
    {
    System.out.println("Exception in mySQL(): " + e.getMessage() );
    }
    Thread.sleep(4800);
    }
    catch (StringIndexOutOfBoundsException e)
    {
    System.err.println(res.getString("samplesmsapp.msg _format:_number:message"));
    }
    catch(Exception ex) { }
    }
    }
    }

    public class SMSQueueThread extends Thread
    {
    private SynchronousQueue smsQueue;
    private String consumerName;
    private PrintStream printStream;
    public SMSQueueThread(String consumerName, SynchronousQueue smsQueue, PrintStream printStream)
    {
    this.consumerName = consumerName;
    this.smsQueue = smsQueue;
    this.printStream = printStream;
    }

    public void run()
    {
    while (true)
    {
    try
    {

    OutMessage poll = (OutMessage)smsQueue.poll(20,TimeUnit.SECONDS);
    printStream.println(this.consumerName + ": " + poll.getMsg() + " " + poll.gethpnumbers());

    // BREAKING NUMBERS INTO TOKENS
    StringTokenizer st = new StringTokenizer(poll.gethpnumbers(),",");

    while (st.hasMoreTokens())
    {
    String sendNum_65 =st.nextToken().trim();
    String sendNum = "65" + sendNum_65;
    System.out.println("Phone = " + sendNum);

    // SEND INDIVIDUAL TOKENS
    try
    {
    System.err.println(res.getString("samplesmsapp.msg :_'") + sendNum + "', '" + poll.getMsg() + "'");
    term.sendMessage(sendNum, poll.getMsg());

    try
    {
    stmt = con.createStatement();
    //stmt.executeUpdate("INSERT INTO records(admission_no,mobile_no,status,datetime) VALUES('"+sendNum_65+"','"+poll.getMsg()+"', now(), 'out')");
    }
    catch (Exception e)
    {
    System.out.println("Exception in mySQL(): " + e.getMessage() );
    }
    Thread.sleep(4800);
    }
    catch (StringIndexOutOfBoundsException e)
    {
    System.err.println(res.getString("samplesmsapp.msg _format:_number:message"));
    }
    catch(Exception ex) {
    ex.printStackTrace();
    }
    }
    }
    catch (InterruptedException ie)
    {
    ie.printStackTrace();
    }
    catch (NullPointerException ne)
    {
    ne.printStackTrace();
    }
    }
    }
    }
    }

    i have use this code but i dnt what i have include following errors are came

    E:\sendSms>javac SMSGateway.java
    SMSGateway.java:8: error: package javax.servlet does not exist
    import javax.servlet.*;
    ^
    SMSGateway.java:9: error: package javax.servlet.http does not exist
    import javax.servlet.http.*;
    ^
    SMSGateway.java:12: error: cannot find symbol
    public class SMSGateway implements SmsListenerInterface
    ^
    symbol: class SmsListenerInterface
    SMSGateway.java:17: error: cannot find symbol
    static SmsTerminal term = null;
    ^
    symbol: class SmsTerminal
    location: class SMSGateway
    SMSGateway.java:23: error: cannot find symbol
    SynchronousQueue<OutMessage> smsQueue = new SynchronousQueue<OutMessage>
    ();
    ^
    symbol: class OutMessage
    location: class SMSGateway
    SMSGateway.java:146: error: cannot find symbol
    public void receiveSms(int statusCode, String errmsg, SmsMsgIncoming msg
    )
    ^
    symbol: class SmsMsgIncoming
    location: class SMSGateway
    SMSGateway.java:23: error: cannot find symbol
    SynchronousQueue<OutMessage> smsQueue = new SynchronousQueue<OutMessage>
    ();
    ^
    symbol: class OutMessage
    location: class SMSGateway
    SMSGateway.java:56: error: cannot find symbol
    res = Utils.getResources();
    ^
    symbol: variable Utils
    location: class SMSGateway
    SMSGateway.java:104: error: cannot find symbol
    term = new SmsTerminal(smsTerminalPort, smsTerminalBitRa
    te, this);
    ^
    symbol: class SmsTerminal
    location: class SMSGateway
    SMSGateway.java:150: error: cannot find symbol
    if(statusCode == SmsTerminal.SC_OK)
    ^
    symbol: variable SmsTerminal
    location: class SMSGateway
    SMSGateway.java:229: error: cannot find symbol
    smsQueue.offer(n
    ew OutMessage(num, msg),10,TimeUnit.SECONDS);

    ^
    symbol: class OutMessage
    location: class SMSGateway.HandleAClient
    SMSGateway.java:259: error: cannot find symbol
    smsQueue.offer(n
    ew OutMessage(num, msg),10,TimeUnit.SECONDS);

    ^
    symbol: class OutMessage
    location: class SMSGateway.HandleAClient
    SMSGateway.java:348: error: cannot find symbol
    OutMessage poll = (OutMessage)smsQueue.poll(20,TimeU
    nit.SECONDS);
    ^
    symbol: class OutMessage
    location: class SMSGateway.SMSQueueThread
    SMSGateway.java:348: error: cannot find symbol
    OutMessage poll = (OutMessage)smsQueue.poll(20,TimeU
    nit.SECONDS);
    ^
    symbol: class OutMessage
    location: class SMSGateway.SMSQueueThread
    14 errors

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: sms coding in java

    error: package javax.servlet does not exist
    You need to find the definition for the package and add it to the classpath for the compiler,

    When the package is found, I suspect many of the rest of the errors will be fixed.

    Please edit your post and wrap your code with code tags:
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Apr 2013
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default java code for sending sms alerts from my webapplication

    i need java code for sending sms alerts to registered users of my web based project

    --- Update ---

    i need java code for sending sms alerts to registered users of my web based project

    --- Update ---

    i need java code for sending sms alerts to registered users of my web based project

  6. #6
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: java code for sending sms alerts from my webapplication

    Quote Originally Posted by swapnareddy View Post
    i need java code for sending sms alerts to registered users of my web based project

    --- Update ---

    i need java code for sending sms alerts to registered users of my web based project

    --- Update ---

    i need java code for sending sms alerts to registered users of my web based project
    We don't write code, we assist you in writing code when you have questions.
    Have you tried what Norm suggested or do you need help with that part? ...or do you have a different problem now?

  7. #7
    Junior Member
    Join Date
    Apr 2013
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: java code for sending sms alerts from my webapplication

    yes i have set the classpath to servlet-api.jar file, but same errors r coming

    --- Update ---

    import java.io.*;
    import java.util.*;
    import java.util.concurrent.SynchronousQueue;
    import java.util.concurrent.LinkedBlockingQueue;
    import java.util.concurrent.TimeUnit;
    import java.net.*;
    import com.joomfire.sms.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.sql.*;
     
    public class SMSGateway implements SmsListenerInterface
     
    {
    	private static java.util.ResourceBundle res;
    	private static final String db_name = "test";
    	static SmsTerminal term = null;
    	private Connection con = null; //for database connection
    	private Statement stmt;
    	private ResultSet rs;
    	private String msgStatus = "";
    	private String check = "";
            SynchronousQueue<OutMessage> smsQueue = new SynchronousQueue<OutMessage>();
     
    	public static void main(String[] args)
    	{
    		new SMSGateway();
    	}
     
    	public SMSGateway()
    	{
    		String str;
     
    		try
    		{
    			Class.forName("com.mysql.jdbc.Driver").newInstance();
    		}
    		catch (Exception e)
    		{
    			System.out.println("Exception in init(): Unable to load JDBC driver");
    		}
     
    		try
    		{
     
    			con = DriverManager.getConnection("jdbc:mysql://localhost:06/winnova", "root", " root");
    		  System.out.println("conn: "+con);
    		}
    		catch (Exception e)
    		{
    			System.out.println("Exception in init(): Unable to establish connection to database '" + db_name + "'");
    		}
     
    		try
    		{
    			res = Utils.getResources();
    		}
    		catch (java.util.MissingResourceException mre)
    		{
    	    	mre.getMessage();
    	    	System.exit(1);
    		}
     
    		str = res.getString("samplesmsapp.SampleSmsApp_starting");
    		System.out.println(str);
     
    		String confFileName = "samplesmsapp.conf";
    		Properties conf = null;
    		FileInputStream confIn = null;
     
    		try
    		{
    			File confFile = new File(confFileName);
    	    	confIn = new FileInputStream(confFile);
    	    	conf = new Properties();
    	    	conf.load(confIn);
    		}
    		catch (IOException e)
    		{
    		System.err.println(res.getString("samplesmsapp.could_not_read_") + confFileName + ": " + e);
    	    	System.exit(1);
    		}
    		finally
    		{
    			try
    			{
    				if(confIn!=null)
    				confIn.close();
    	    	}
    	    	catch (IOException e) { ; }
    		}
    		System.out.println(res.getString("samplesmsapp.-_configuration_read"));
     
    		// get configuration parameter values.
    		String smsTerminalPort = conf.getProperty("smsTerminalPort");
    		int smsTerminalBitRate = Integer.parseInt(conf.getProperty("smsTerminalBitRate"));
    		boolean includeSmscInfoLen = new  Boolean(conf.getProperty("includeSmscInfoLen")).booleanValue();
    		String smscAddress = conf.getProperty("smscAddress");
     
    		System.err.println(res.getString("samplesmsapp.-_connecting_to_SMS_terminal._please_wait."));
     
    		try
    		{
    			term = new SmsTerminal(smsTerminalPort, smsTerminalBitRate, this);
    			term.initialize();
    		    if(includeSmscInfoLen)
    		    {
    				term.setMsgOutIncludeSmscAddrLen(includeSmscInfoLen);
    				if(smscAddress != null)
    					term.setMsgOutSmscAddr(smscAddress);
    		    }
    		}
    		catch (Exception e)
    		{
    			str=res.getString("samplesmsapp.unable_to_create_a_SmsTerminal");
    			System.err.println(str);
    			System.err.println(res.getString("samplesmsapp.msg:_") + e);
    			System.exit(1);
    		}
     
    		//Create new smsQueue thread here
    		SMSQueueThread smsQueueThread = new SMSQueueThread("SMS Queue Thread", smsQueue, System.out);
    		smsQueueThread.start();
     
    		str = res.getString("samplesmsapp.-_connected_to_terminal");
    		System.out.println(str);
     
    		try
    		{
    			ServerSocket ss = new ServerSocket(4444);
    			System.out.println("Server started... waiting for Client...");
     
    	  		while(true)
    	  		{
    	  			Socket connectToClient = ss.accept();
    	  				HandleAClient thread = new HandleAClient(connectToClient);
    	  			thread.start();
    			}
     		}
    		catch(IOException ex)
    		{
    			System.err.println(ex);
    		}
    	}
     
    	public void receiveSms(int statusCode, String errmsg, SmsMsgIncoming msg)
     
    	{
     
    		if(statusCode == SmsTerminal.SC_OK)
    			{
    			System.out.println(res.getString("samplesmsapp.msg_received:_") + msg.toString());
     
     
    			// Recieved SMS & HP
    			String rAdm = msg.getMessage();
    			String rNum = msg.getSenderNumber();
     
    			System.out.println("Recieve Message : " + rAdm);
    			System.out.println("Recieve Number : " + rNum);
     
    			// INSERT SMS & HP INTO DATABASE
    			try {
     
    				String xxx;
    				xxx="";
    				System.out.println("+65 ooo : " + xxx);
    				stmt = con.createStatement();
    				//stmt.executeUpdate("INSERT INTO records(sms_id,admission_no,mobile_no,status,datetime) VALUES(null,'"+rAdm+"','"+rNum.substring(3, rNum.length())+"','in', now())");
     
     
    			}
    			catch (Exception e)
    			{
    				System.out.println("Exception in mySQL(): " + e.getMessage() );
    			}
    		}
    		else
    		{
    			System.err.println(res.getString("samplesmsapp.error_receiving_SMS_message:_") + errmsg);
    		}
    	}
     
    	public void destroy()
    	{
    		try {
    			if (con != null)
    				con.close();
    		}
    		catch (SQLException excIgnored){}
    	}	// End destroy()
     
     
    	class HandleAClient extends Thread
    	{
    		private Socket connectToClient;
     
    		public HandleAClient(Socket socket)
    		{
    			this.connectToClient = socket;
    		}
     
    		public void run()
    		{
     
    			synchronized(connectToClient)
    			{
    				try
    					{
    					BufferedReader fromClient = new BufferedReader(new InputStreamReader(connectToClient.getInputStream()));
    					PrintWriter toClient = new PrintWriter(connectToClient.getOutputStream(), true);
     
    					String selection, outputLine;
    					while ((selection = fromClient.readLine()) != null)
    					{
    						String msg = "";
    						String num = "";
     
    						if(selection.equals("phone"))
    						{
    							// RECIEVE NUMBERS AND MSG FROM SERVLET
    							num = fromClient.readLine();
    							msg = fromClient.readLine();
     
    							System.out.println("Phone = " + num);
    							System.out.println("Message = " + msg);
     
    							try {
    								smsQueue.offer(new OutMessage(num, msg),10,TimeUnit.SECONDS);
    							}
    							catch (InterruptedException ie)
    							{
    								ie.printStackTrace();
    							}
     
    						//	SendSMS sms = new SendSMS(num, msg);
    						//	sms.start();
    						}
    						else
    						{
    							// RECIEVE GROUP AND MSG FROM SERVLET
    							String group = fromClient.readLine();
    							msg = fromClient.readLine();
     
    							System.out.println("Group : "+group);
     
    							try
    							{
    								stmt = con.createStatement();
    							//	rs = stmt.executeQuery("SELECT mobile_no FROM student WHERE course = '"+group+"'");
     
    								while(rs.next())
    								{
    									num = num + rs.getString(1) + ",";
    								}
     
    								System.out.println("Numbers = " + num);
     
    								smsQueue.offer(new OutMessage(num, msg),10,TimeUnit.SECONDS);
     
    							//	SendSMS sms = new SendSMS(num, msg);
    							//	sms.start();
    							}
    							catch (Exception e) {
    								e.printStackTrace();
    							}
    						}
    					}
    				}
    				catch(IOException ex)
    				{
    					System.err.println(ex);
    				}
    			}
    		}
    	}
     
    	class SendSMS extends Thread
    	{
    		private String num;
    		private String msg;
     
    		public SendSMS(String numbers, String message)
    		{
    			num = numbers;
    			msg = message;
    			System.out.println("Message = " + message);
    		}
     
    		public void run()
    		{
    			// BREAKING NUMBERS INTO TOKENS
    			StringTokenizer st = new StringTokenizer(num,",");
     
    			while (st.hasMoreTokens())
    			{
     
    				String sendNum_65 =st.nextToken().trim();
    				String sendNum = "65" + sendNum_65;
    				System.out.println("Phone = " + sendNum);
     
    				// SEND INDIVIDUAL TOKENS
    				try
    				{
     					System.err.println(res.getString("samplesmsapp.msg:_'") + sendNum + "', '" + msg + "'");
    					term.sendMessage(sendNum, msg);
     
    					try
    					{
    						stmt = con.createStatement();
    					    //stmt.executeUpdate("INSERT INTO smsrecords(admission_no,mobile_no,status,datetime)  VALUES('"+sendNum_65+"','"+msg+"', now(), 'out')");
     
    										}
    					catch (Exception e)
    					{
    						System.out.println("Exception in mySQL(): " + e.getMessage() );
    					}
    					Thread.sleep(4800);
    				}
    				catch (StringIndexOutOfBoundsException e)
    				{
    					System.err.println(res.getString("samplesmsapp.msg_format:_number:message"));
    				}
    				catch(Exception ex) { }
    			}
    		}
    	}
     
                public class SMSQueueThread extends Thread
    	{
    		private SynchronousQueue smsQueue;
    		private String consumerName;
    		private PrintStream printStream;
    		public SMSQueueThread(String consumerName, SynchronousQueue smsQueue, PrintStream printStream)
    		{
    			this.consumerName = consumerName;
    			this.smsQueue = smsQueue;
    			this.printStream = printStream;
    		}
     
    		public void run()
    		{
    			while (true)
    			{
    			  try
    			  {
     
    			    OutMessage poll = (OutMessage)smsQueue.poll(20,TimeUnit.SECONDS);
    			    printStream.println(this.consumerName + ": " + poll.getMsg() + " " + poll.gethpnumbers());
     
    				// BREAKING NUMBERS INTO TOKENS
    				StringTokenizer st = new StringTokenizer(poll.gethpnumbers(),",");
     
    				while (st.hasMoreTokens())
    				{
    					String sendNum_65 =st.nextToken().trim();
    					String sendNum = "65" + sendNum_65;
    					System.out.println("Phone = " + sendNum);
     
    					// SEND INDIVIDUAL TOKENS
    					try
    					{
     						System.err.println(res.getString("samplesmsapp.msg:_'") + sendNum + "', '" + poll.getMsg() + "'");
    						term.sendMessage(sendNum, poll.getMsg());
     
    						try
    						{
    							stmt = con.createStatement();
    							//stmt.executeUpdate("INSERT INTO records(admission_no,mobile_no,status,datetime)  VALUES('"+sendNum_65+"','"+poll.getMsg()+"', now(), 'out')");
    								}
    						catch (Exception e)
    						{
    							System.out.println("Exception in mySQL(): " + e.getMessage() );
    						}
    						Thread.sleep(4800);
    					}
    					catch (StringIndexOutOfBoundsException e)
    					{
    						System.err.println(res.getString("samplesmsapp.msg_format:_number:message"));
    					}
    					catch(Exception ex) {
    						ex.printStackTrace();
    					}
    				}
    			  }
    			  catch (InterruptedException ie)
    			  {
    			    ie.printStackTrace();
    			  }
    			  catch (NullPointerException ne)
    			  {
    			    ne.printStackTrace();
    			  }
    			}
    		}
    	}
    }


    --- Update ---

    i have sent code for it please give me instruction what i have to include


    thanks in advance

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: sms coding in java

    Where is this package defined: com.joomfire.sms?
    Where is the class: OutMessage defined?
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. SMS from Java
    By Susanto in forum Java Theory & Questions
    Replies: 0
    Last Post: October 19th, 2012, 09:15 AM
  2. receive flash sms, ozeki ng, java
    By fosha in forum Java Theory & Questions
    Replies: 0
    Last Post: May 12th, 2012, 11:47 AM
  3. Replies: 2
    Last Post: February 19th, 2012, 07:36 AM
  4. Sending SMS in java
    By pipi in forum What's Wrong With My Code?
    Replies: 12
    Last Post: January 26th, 2011, 08:10 PM
  5. Help me in java coding
    By smallmac in forum Java Theory & Questions
    Replies: 5
    Last Post: August 2nd, 2010, 09:50 AM