Jon Parise

Ranch Hand
+ Follow
since Jul 03, 2007
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Jon Parise

Thanks for letting me know about Commons. I'll give that a try, it does appear to be easier to use.

I am still curious about getting Java Mail to send nice attachments, so if anyone has a solution I would be interested to see.

Thanks again,

Jon
13 years ago
Sorry for the double post, but I wanted to add something.

Boxes usually mean that your data is not getting encoded right. How are you building you Java packets? Could you show us the code?

Sometimes if a packet is not built correctly you will get boxes like that.
It sounds to me like you just need to make your own communications protocol(not as scary as it sounds). Basically, you need a language that the client and server will share and communicate using.

You'll want to do this over TCP/IP using socket connections. Have the Server constantly listen for connections and accept them. Then simply have the client make a connection to the server.

Once connected, you need some messages that they both understand. You can encode these however you want as binary data or even just using ascii strings(they get sent as binary).

The first step is to determine what data will be passed back and forth and how. For example consider a weather application. Say the server monitored weather in the whole country and the client coudl ask for the weather in a specific locations.

You could do something like this:

Client connects
Sever accepts connection
Client sends request: GET Weather Pittsburgh,PA
Server processes the request lookign up teh weather
Client listens for a response
Server sends back information:TEMP 24, WIND SE 10MPH
Client receives data
Client closes connection
CLient updates display.

This is just a very basic pseudo code example, but that is basically how it can be done. Obviously the protocol should be much more robust.

Hope that helps,

Jon
Hello everyone,

I'm working on adding some e-mailing capability to an existing reporting application.

I am able to generate a report and send it using JavaMail, however I can't seem to get the MIME types right. Know know the 5 MIME types I needs for the 5 formats I support, but they all are sent as .dat files. Upon arrival, if I convert the .dat file to the proper extensions(On Windows) then I can open the file just fine.

I tries using the MIMEBodyPart class's setContent method, but it keeps telling me:

javax.activation.UnsupportedDataTypeException: no object DCH for MIME type application/pdf



It says the same for all my other MIME Types, expect with the correct MIME type listed.

Here is the code:



Please note that getMIMEHeader returns a new javax.mail.Header object that has the value set to the MIMtype String.

Also, recipients is an ArrayList of type String that contains a listing of everyone the e-mail should be send to.

Thanks,

Jon
[ December 09, 2008: Message edited by: Jon Parise ]
13 years ago
I ended up just uninstalling and reinstalling all of Netbeans...

I will think twice before clicking the update button again. Thanks for the info.

Everything is working again for now.
Hey everyone,

I have a Java SE 6 project I built using Netbeans 6.1. Today Netbeans told me it had some updates, so I installed them. One of them was for Ant.

Now when I try to build my project I get the following:

ERROR - Ant is misconfigured and cannot be run.
java.lang.ClassNotFoundException: org.apache.tools.ant.input.InputHandler
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at org.apache.tools.ant.module.bridge.AuxClassLoader.findClass(AuxClassLoader.java:85)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:247)
at org.apache.tools.ant.module.bridge.AntBridge.createAntInstance(AntBridge.java:283)
at org.apache.tools.ant.module.bridge.AntBridge.getAntInstance(AntBridge.java:264)
at org.apache.tools.ant.module.bridge.AntBridge.getInterface(AntBridge.java:253)
at org.apache.tools.ant.module.run.TargetExecutor.run(TargetExecutor.java:460)
at org.netbeans.core.execution.RunClassThread.run(RunClassThread.java:151)



I'm not sure what the issue is, does anyone have any suggestions?

Thanks.
I actually thought it was fixed last time, but it showed up again.

After using the debugger it dawned on me what my issue was.

I was creating my times using the Calendar class and just using Calendar.getInstance(). The problem is that I get a different Year, month and day portion of the calendar each day it is run.

I now normalize the calendar and use it like so:



From there I created a new calendar with just the hour, minute and second portions changed:



Now 8:00:00 is always represented by the same long no matter when it is created.

Hopefully this helps someone else out someday.
I figured it out.

In one obscure place buried deep in the code I had accidentally built my time as minute hour second...

That causes the problem.

I fixed that and now compareTo is working just fine. Funny how that works....

So the world is as it should be again and I am not going insane. Once again 4:00 is before 7:00.

Thanks to all those that helped!
[ August 29, 2008: Message edited by: Jon Parise ]

Originally posted by Scott Selikoff:
If you're seeing something odd its probably related to time zone. Keep in mind everything is stored in UTC internally, but when its read it may be converted to what it 'thinks' is your local.

Make sure your viewing things in a consistent format such as UTC. That's part of why I prefer the epoch getTime() long value... its a number always calculated in UTC.



What's odd though is in the database it is store specifically without a time zone. Also, the two columns are inserted at the exact same time...

Internally something is certainly different.
Well I printed the results of the get time methods, here is what I get:

First Set:
Start:04:00:00Get Time: 32400000 End:00:07:00 Get Time:18420000

Second Set
Start:07:00:00Get Time: 43200000 End:04:00:00 Get Time:32400000

So something is making them behave strangely.

I'm using a PostgreSQL database version 8.2.

The table has both the columns created as time without a time zone. Here is my create table:



Anyone have any insights?
Thanks for the suggestion, I didn't think of comparing the get time values..perhaps by looking at them I will see something.


The reason I am using time is that this is for a production shift. So the user enters a shift name, start time, end time and the days of the week it is valid for.

The days of the week are taken care of by a String.

I really don't need a timestamp or a date in this case I just need a time. Nothing else matters in the variable. The date portion would have no meaning really in this instance.


I'll check the getTime() values when I get to work. At least I know I can fall back on the string split method, but it seems like an ugly hack.
I did read that, and I am aware of the 3 types. I just don't understand why 4:00 is coming out as greater than 7:00...

I know java.sql.time is just a wrapper around Date so maybe the Date portions are different.

I think the easiest solution for me may be to just use String.Split to break the hours, mins and seconds out and do the comparison that way.

If anyone has a better method let me know.

Thanks,

Jon
What you need here is what is typically called a Singleton. You need a class that handles the database that there can only ever be one instance of.

What you need to do is create a class to wrap you database.



That should only allow 1 connection to the database. You use it like this:

DBHandler dbHandler = DBHandler.getInsatnce();

dbHandler.connect();
ResultSet rs = dbHandler.executeQuery("SELECT * FROM BLAH");
dbHandler.disconnect();
Hey everyone,

I have two Java.Sql.Time variables, one called startTime and one called endTime. The user passes them in to a function.

In that function I need to handle things differently depending on if startTime > endTime or not. Since time can wrap around, something could start at 9:00pm or 21:00:00 and end at 7am 7:00:00.

I use the following:

if(startTime.compareTo(endTime) < 0){
//Do Stuff
}

However, even when startTime is 0:00:00 and endTime is 23:00:00 I always get a 1 as the result of the compareTo call indicating that startTime is greater than endTime.

I'm not sure what the solution is, I tried turning the two times into GregorianCalendars, but I am not sure how.

Any help would be great!

Thanks!