Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,160,480 members, 7,843,468 topics. Date: Wednesday, 29 May 2024 at 06:09 AM

Java: Help! - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Java: Help! (2380 Views)

C Or Java Help Needed! / Java Help / Head First Java - Help (2) (3) (4)

(1) (Reply) (Go Down)

Java: Help! by adewaleafolabi(m): 8:40pm On Jun 22, 2010
Hi,
I wrote an application in java and i neet to send sms from within this application using any bulk sms company. Most offer API's for phpmand aspx. Could some one point me in the right direction.
Also I am able to export my Jtable as an excel worksheet but i'd like to know how to send this file to the printer from inside java.

Thanks,
Afolabi
Re: Java: Help! by xtraodinaire: 9:34am On Jun 23, 2010
For the sms api most bulk sms companies only support php but i few like clickatell nd simplewire support java,
To print your table from u application, use:

try{
//title of d document.
MessageFormat mf=new MessageFormat("Title"wink;

//footer, here we are gon number d document,

MessageFormat foot=new MessageFormat("-{0}-"wink;

table.print(JTable.PrintMode.FIT_WIDTH,mf, foot);
}
catch(PrinterException pe)

{
System.out.println(pe);
}

Note that it works wit java 5.0+,
And to export to excel, u can just add all d content to an hidden textarea and separate with a tab i.e '\t' then save as csv or as xls, if u save as xls u get a warnin when you open the xls file but no harm done,
Sure u knw xls is d excel format,

Hope it helped a lil,
Re: Java: Help! by adewaleafolabi(m): 1:26pm On Jun 24, 2010
Thanks i'd get in touch with clickatell.
But it seems you didn't quite understand my other problem.
I can read write export to excel using jexcel api. What i need is how to send this excel file to the printer
Re: Java: Help! by xtraodinaire: 3:12pm On Jun 24, 2010
oh, my bad, just read ur post again, if u tryin to print d excel document den after exporting the doc to excel den u can print in excel now or if after exporting, the application will den open the excel document using

String path="System path e.g mama\papa";

String hd = "filename e.g doc.xls";

Runtime.getRuntime().exec(new String[] {"cmd", "/C", "start", "\"\"", path+hd});

dt will automatically open d document den u cn use d print function in excel, but if u want to print d document witout openin it den i have no idea on hw to do dat except u just print ur JTable,
Re: Java: Help! by adewaleafolabi(m): 6:22pm On Jun 24, 2010
thanks,
printing my jtable would have been a wonderful option if only swing could some how print it just like the way excel would render the same table to the printer.
Re: Java: Help! by Beaf: 8:12pm On Jun 24, 2010
jni4net is your answer. Its an open source bridge between .NET and Java. So you can download a .NET sms dll and use it from your Java code.
http://jni4net.sourceforge.net/

If you are working with webservices, then you need to watch encoding (UTF-8 and UTF-16).
Re: Java: Help! by xtraodinaire: 9:37pm On Jun 24, 2010
well, u havent tried d code i sent for printin d table den, it prints ur table just like u have it but the things's dat it comes out with dis annoying header size, but if u trust ur own table designs and all dat, u can just add ur table to a panel and not add a scrollpane to d table but the panel instead den u can print the panel using the printjob stuff and it cmes out gud, can u drop a screenshot of what you have and what you intend to achieve?? i have a veri nice class i use for printin documents and all,
Re: Java: Help! by adewaleafolabi(m): 5:47pm On Jun 25, 2010
Hi,
This is what i intend to achieve

Re: Java: Help! by xtraodinaire: 6:04pm On Jun 25, 2010
well you can still print ur jtable directly though, but if you want your printout to look like the second screenshot, then you just need to adjust your table properties like removing the gridlines and setting the viewport background to white and u can use html tags to increase the size of ur headers,

**but i think u shuld keep the gridlines though** just my opinion, lol
Re: Java: Help! by adewaleafolabi(m): 11:15am On Jun 27, 2010
Thanks. That wud solve it. Also how do i encrypt a string using md5 .
My app connects to a remote database. But i think everything is sent as plain text is there a way to encrypt this data using ssl or any other.
Re: Java: Help! by xtraodinaire: 3:23pm On Jun 27, 2010
i use SHA but it works d same way with MD5 so try dis code i used a long time ago, it should work out,


String sessionid="12345";

byte[] defaultBytes = sessionid.getBytes();
try{
MessageDigest algorithm = MessageDigest.getInstance("MD5"wink;
algorithm.reset();
algorithm.update(defaultBytes);
byte messageDigest[] = algorithm.digest();

StringBuffer hexString = new StringBuffer();
for (int i=0;i<messageDigest.length;i++) {
hexString.append(Integer.toHexString(0xFF & messageDigest[i]));
}
String foo = messageDigest.toString();
System.out.println("sessionid "+sessionid+" md5 version is "+hexString.toString());
sessionid=hexString+"";
}catch(NoSuchAlgorithmException nsae){

}
Re: Java: Help! by adewaleafolabi(m): 5:21pm On Jun 29, 2010
Thanks, to all of you, you've helped me greatly an am so grateful. Still have a problem with the sms integration though. Simplewire doesn't seem to be nigerian bulk sms companies. Web2sms has a gateway like this
www.web2smspro.com/confirm_reseller_voting.asp?phonenumber=0803xxxxxxx&url=www.yourwebserveraddress.com&username=user&password=1234&senderid=web2smspro&countrycode=234&message=Testing

how do i integrate this into java. is it sensible for instance am sending 1000 sms at once to use this http wouldn't that kill their server? or lead to denial of service for me.

This is the last end of my app. Thanks
Re: Java: Help! by xtraodinaire: 6:22pm On Jun 29, 2010
all of 'em use http but i dnt think it will be an easy task to send to more dan one number @a time maybe u gon have to create a thread dt changes the number each time d a message is sent so u can send anoda as long as u not waitin to get delivery report though,

Did you try clickatell?? cos i know that is very easy it use, and u cn send to nigerian networks too,
Re: Java: Help! by adewaleafolabi(m): 7:49am On Jun 30, 2010
I looked at clickatell's pricing and it wasn't encouraging. I checked smslive247 and it seems they support SOAP webservice but i don't have a clue on how to call a web service
Thankls
Re: Java: Help! by xtraodinaire: 1:22pm On Jun 30, 2010
yea, clickatell is not all dt pocket friendly sha, just do ur research about the webservice thing cos i'm not so familiar with it,
Re: Java: Help! by saperpsms: 5:31pm On Jul 02, 2010
Hey man. I just saw this thread and my time is up for the day and for the week.

If you haven't figured this out by Monday holla me and I will send you the Java solution used by us through Henox ICT gateway first thing Monday morning.

Their rates and bulk sms capabilities are excellent. You can check them out here

http://www.henoxict.com

Cheers!
Re: Java: Help! by adewaleafolabi(m): 10:05am On Jul 03, 2010
whoa thanks i'd be expecting ur reply on monday
Re: Java: Help! by adewaleafolabi(m): 3:03pm On Jul 09, 2010
hi,
Thanks to u guys i've been able to make the application work. I am in a little problem. I have a textfile that contains numbers in this format
0809747647864
487484974974984
984894949894984
984894949894984

I need java to delete duplicate line entries. I tried searching but didn't get anything useful even unix sort didn't seenm to work
Re: Java: Help! by adewaleafolabi(m): 9:11pm On Jul 10, 2010
this problem was solved by this class

import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintStream;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.Set;
import javax.swing.JFileChooser;
import javax.swing.JFrame;

/**
*
* @author groovicus
*
* Use this however you want.
*/
public class replace extends JFrame{

Set set = new LinkedHashSet();

public void replace(){

String filename = "";
JFileChooser fc = new JFileChooser(new File(filename));

fc.showOpenDialog(this);
File selFile = fc.getSelectedFile();

try {
BufferedReader in = new BufferedReader(new FileReader(selFile));
String str;
while ((str = in.readLine()) != null) {
set.add(str);
}
in.close();
} catch (IOException e) {
}

try {
FileOutputStream out = new FileOutputStream(selFile);

Iterator it = set.iterator();

while (it.hasNext()) {
String element = (String)it.next();
PrintStream p = new PrintStream( out );
p.println(element);
}

out.close();
} catch (IOException e) {
}

//System.exit(0);
}


}
Re: Java: Help! by saperpsms: 4:57pm On Jul 14, 2010
@adewaleafolabi

Glad to know the app works. Did you find the material I sent to you useful?

Cheers!
Re: Java: Help! by adewaleafolabi(m): 9:30am On Jul 17, 2010
Thanks, i did find it useful
Re: Java: Help! by adewaleafolabi(m): 10:39am On Jul 29, 2010
Hi,
Emergency
Okay everything works great and fine but there's a small issue that just arose. Now i want this app not to connect to the local mysql server running on my machine but instead connect to a database running on the my website.
From the cpanel i created the neccessary users, database, tables etc . I also set access control to allow %%%.%%%.%%%
However mysql jconnector return connection refussed
HELPPPPPPPPPPP

grin
got to hurry to class now. for 11:00am and am yet to prepare. grin

Thanks
Re: Java: Help! by SayoMarvel(m): 1:38pm On Jul 30, 2010
How come I'm left out of this. Read the whole file, tokenize it, add each token to a suitable data structure that does not allow duplicates. After doing that, read out the data in the date structure (by now the duplicates should be eliminated), use the Formatter class to assemble the data the way you want them, set the formatted output on a JTextArea, call the write() method of JTextArea. Bingo! You now have a plain text file that contains no duplicate.
You can do futher reading on JAVA HOW TO PROGRAM 7th EDITION (by Deitel), Chapter 14 (Files and Streams) and Chapter 19 (Java Collections FrameWork). Have a nice day.
Re: Java: Help! by saperpsms: 12:30pm On Aug 06, 2010
Java How To Program by Deitel & Deitel is a great book. But I think at poster has passed this stage.

Cheers!
Re: Java: Help! by xtraodinaire: 4:06pm On Aug 06, 2010
i use the mysql-connector-java-5.0.7-bin, the u just use the dsame process but change ur ipaddress, e.g

String driver = "com.mysql.jdbc.Driver";

String url = jdbc:mysql://74.125.94.147:3306/store (your database name is store here and notice the case, it can be case sensitive and you should always add d port number :3306 else it wont connect).

String uname ="root";
String pass = "pass";

Class.forName(driver);
Connection con = DriverManager.getConnection(url, uname, pass);

thats d step but you can create a 'wait dialog' so that the user will know the request is being processed by the server because since you are connecting to the internet, its gon b slow a bit,

Hope it helps,
Re: Java: Help! by SayoMarvel(m): 10:21pm On Aug 10, 2010
If @poster cannot perform plain text file processing, he/she has not passed the stage of Deitel Deitel. Better still, there is a book Java IO, it digs really deep into streams in java (including File Processing, Networking, Serial Programming e.t.c). I think that is more advance. I didn't mean to underestimate your expertise @poster. Happy coding.
Re: Java: Help! by adewaleafolabi(m): 7:21pm On Aug 15, 2010
thanks hmm its being a while. The problem wasn't from me as i found out later that the webhost had blocked the port 3306 for **security reasons**. So all the while it wasn't from moi. All the same thank you.

(1) (Reply)

Complete Programming Tutorial For Beginner's / Let Learn Android Programming Togather / Oracle Primavera P6-introduction To Basic Pdf(with Screenshots) Free

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 36
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.