JAVA Programing, MySQL, Database, java swing, java printer, ASP.NET, C#.NET, Android, GPhone, iphone, blackberry
Thursday, May 29, 2008
Google Maps on GWT 1.5
Now GWT 1.5 RC is avaliable but GWT Google Map can not work on its.
So I modify something for GWT 1.5. It works fine as run on GWT 1.4.x, you can download here
http://file.citec.us/download.php?id=769C5AD6
Tuesday, May 27, 2008
How to get Primary Keys with DB2
Code Example:
DatabaseMeataData dbmd = conn.getMetaData();
ResultSet rs = dbmd.getPrimaryKeys(catalog, schema, tablename);
But when your database is DB2. You cann't use DatabaseMetaData (The method can be executed, but it returns an empty ResultSet)
ref :http://publib.boulder.ibm.com/infocenter/dzichelp/v2r2/index.jsp?topic=/com.ibm.db29.doc.java/rjvjdapi.htm in Table 11
You can use this solution :
This solution select column name of primary key from syscat.keycoluse and syscat.tabconst of DB2.
String SqlStatement = "select colseq, colname from syscat.keycoluse k, syscat.tabconst t where k.constname = t.constname and k.tabname = t.tabname";
conn = Connector.getDBConnection(url, username, password);
pstm = conn.prepareStatement(SqlStatement);
rs = pstm.executeQuery();
ref : http://www-128.ibm.com/developerworks/db2/library/techarticle/dm-0401melnyk/?S_TACT=105AGX11&S_CMP=LP in Table 1
Monday, May 26, 2008
Send SMS by using Java
Code:
import java.io.*;
import java.util.*;
import javax.comm.*;
public class GSMConnect implements SerialPortEventListener, CommPortOwnershipListener {
private String comPort = "COM3"; // This COM Port must be connect with GSM Modem or your mobile phone
private String messageString = "";
private CommPortIdentifier portId = null;
private Enumeration portList;
private InputStream inputStream = null;
private OutputStream outputStream = null; private SerialPort serialPort;
/** Creates a new instance of GSMConnect */
public GSMConnect(String comm) {
this.comPort = comm;
}
public boolean init() {
portList = CommPortIdentifier.getPortIdentifiers();
while (portList.hasMoreElements()) {
portId = (CommPortIdentifier) portList.nextElement();
if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL){
if (portId.getName().equals(comPort)) {
return true;
}
}
}
return false;
}
public void checkStatus() {
send("AT+CREG?\r\n");
}
public void dial(String phoneNumber) {
try {
//dial to this phone number
messageString = "ATD" + phoneNumber + ";\n\r";
outputStream.write(messageString.getBytes());
} catch (IOException e) {
e.printStackTrace();
}
}
public void send(String cmd) {
try {
outputStream.write(cmd.getBytes());
} catch (IOException e) {
e.printStackTrace();
}
}
public void sendMessage(String phoneNumber, String message) {
send("AT+CMGS=\"" + phoneNumber + "\"\r\n");
send(message + '\032');
}
public void hangup() {
send("ATH\r\n");
}
public void connect() throws NullPointerException {
if (portId != null) {
try {
portId.addPortOwnershipListener(this);
serialPort = (SerialPort) portId.open("MobileGateWay", 2000);
} catch (PortInUseException e) {
e.printStackTrace();
}
try {
inputStream = serialPort.getInputStream();
outputStream = serialPort.getOutputStream();
} catch (IOException e) {
e.printStackTrace();
}
try {/** These are the events we want to know about*/
serialPort.addEventListener(this);
serialPort.notifyOnDataAvailable(true);
} catch (TooManyListenersException e) {
e.printStackTrace();
}
//Register to home network of sim card
send("ATZ\r\n");
} else {
throw new NullPointerException("COM Port not found!!");
}
}
public void serialEvent(javax.comm.SerialPortEvent serialPortEvent) {
switch (serialPortEvent.getEventType()) {
case SerialPortEvent.BI:
case SerialPortEvent.OE:
case SerialPortEvent.FE:
case SerialPortEvent.PE:
case SerialPortEvent.CD:
case SerialPortEvent.CTS:
case SerialPortEvent.DSR:
case SerialPortEvent.RI:
case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
case SerialPortEvent.DATA_AVAILABLE:
byte[] readBuffer = new byte[2048];
try {
while (inputStream.available() > 0) {
int numBytes = inputStream.read(readBuffer);
}
//print response message
System.out.print(new String(readBuffer));
} catch (IOException e) {}
break;
}
}
public void ownershipChange(int type) {
switch (type) {
case CommPortOwnershipListener.PORT_UNOWNED:
System.out.println(portId.getName() + ": PORT_UNOWNED"); break;
case CommPortOwnershipListener.PORT_OWNED:
System.out.println(portId.getName() + ": PORT_OWNED"); break;
case CommPortOwnershipListener.PORT_OWNERSHIP_REQUESTED:
System.out.println(portId.getName() + ": PORT_INUSED"); break;
}
}
public static void main(String args[]) {
GSMConnect gsm = new GSMConnect(comPort);
if (gsm.init()) {
try {
gsm.connect();
gsm.checkStatus();
Thread.sleep(5000);
gsm.sendMessage("Mobile Phone Number", "Your Message");
Thread.sleep(20000);
gsm.hangup();
} catch (Exception e) { e.printStackTrace(); }
} else {
System.out.println("Can't init this card");
}
}
}
Wednesday, May 14, 2008
JavaFX Ep2 : "Hello World"
New Project> JavaFx> JavaFx Script Application
Let's start like instructed by trying to run the Hello World example featured on the JavaFX tutorial page.
import javafx.ui.*;
Frame {
title: "Hello World JavaFX"
width: 250
height: 50
content: Label {
text: "Hello World. From Javalobby!"
}
visible: true
}
This code uses the declarative source code "annotation", it is also possible to use the procedural source code "annotation".
var win = new Frame();
win.title = "Hello World JavaFX";
win.width = 250;
win.height = 50;
var label = new Label();
label.text = "Hello World. From Javalobby!";
win.content = label;
win.visible = true;
[JavaFX Tutorial]Getting start JavaFX with Netbeans IDE 6.1
- Download and Install Netbeans IDE 6.1
- Download this Developmental built of the JavaFx Netbeans 6.1 plugin that base on OpenJFX compiler.
- Unzip the local file
- In Netbeans program Main Menu Choose Tool>Plugin.
- Select Downloaded tab and click Add Plugins.
- Select all the
.nbm
files included in the downloaded bits, and click Open. - Restart the IDE.
NetBeans IDE: Adding/Changing JVM command line args
You can indeed set your favorite JVM command line args to use with NetBeans. Here's how to do it.
1. Go to the directory where you installed NetBeans IDE.
2. In that directory, go to the 'etc' directory.
3. In that 'etc' directory, there is a file called 'netbeans.conf'.
Open that netbeans.conf file
Here's an explanation of the command line switches I use:
-J-Xms128m -> initial Java heap size
-J-Xmx384m -> max Java heap size
-J-XX:NewRatio=20 -> Ratio of old generation to young generation space
-J-XX:+UseConcMarkSweepGC -> use the concurrent old generation garbage collector
-J-XX:+UseParNewGC -> use the parallel young generation garbage collector
-J-XX:+CMSPermGenSweepingEnabled -> enable concurrent gc in permanent generation
-J-XX:+CMSClassUnloadingEnabled -> enable class unloading in permanent generation with the concurrent gc collector
-J-XX:+CMSPermGenPrecleaningEnabled -> enable pre-cleaning when using concurrent gc collector in permanent generation
-J-XX:PermSize=64m -> initial size of permanent generation space set to 64m
-J-XX:MaxPermSize=96m -> max size of permanent generation space set to 96m
-J-Dswing.aatext=true -> use font anti-aliasing
* Keep in mind that I am running on a machine with 1G of RAM. However, these settings should work fine on a machine with 512m. Just keep an eye on swapping activity. If you can keep your system from swapping, you're responsiveness will be much better.
Thursday, May 8, 2008
Gwt-Ext lib in Netbeans
I found this problem in netbeans 5.5. even if you add Gwt-Ext in your project and following step from getting started, the application didn't work. and show this error.
[ERROR] Out of memory; to increase the amount of memory, use the -Xmx flag at startup (java -Xmx128M ...)
[ERROR] Build failed
this is solution.
http://www.gwt-ext.com/forum/viewtopic.php?f=5&t=755
GWT (Google Web Toolkit)
Get GWT : http://code.google.com/webtoolkit/
GWT plugin for Netbeans : https://gwt4nb.dev.java.net/
GWT plugin for Eclipse : http://code.google.com/p/cypal-studio/
GWT more look and feel , GWT-Ext: http://code.google.com/p/gwt-ext/
GWT e-book you can downloadfrom : http://www.ebookee.com/ such as GWT in Action
That is now i had collected. When i have cool ideas or sample you will see in my blog.
Intercommunication programming
c# detect usb device event
i found my solution at here. How to detect a USB Device and i can finished my c# program
this my video how it work?. AutoDump
if you want my program plz contact me.
Font Thai in mysql like ??? on Ubuntu
Ubuntu 7.04
mysql 5.0.38
If you see Thai font like ??????. because character set in mysql server and client was different.
You should set character set in server and client matched.
Check status in mysql.
In your computer No.2 may be latin. I had changed from latin to tis620.
First, You should edit file config in /etc/mysql/my.cnf and add default-character-set in
[client]
default-character-set = tis620
And....
[mysqld]
default-character-set = tis620
init_connect = 'SET NAMES tis620'
Save it and restart mysql with /etc/init.d/mysql restart
Thai font will be fixed
Nmap scan port
This example on my computer(satann)
if you want to know port just use nmap. and anything what to do..........
my command --> nmap -sT ip
result
Android Contact Management Example Code
http://groups.google.com/group/android-developers/browse_thread/thread/c68dac6a3b38f4ad