I will discuss about the java connection to the Mysql database.
To be more easy in practice, I will give the source code and follow the steps, though more smoothly...
1. download the database here
2. download the source code here (opened with netbeans)
3. Create a data base with the name "testkon" and import the data base that you downloaded in step one
Try to Run .. if there is trouble, please ask ... :-)
Tampilkan postingan dengan label Java. Tampilkan semua postingan
Tampilkan postingan dengan label Java. Tampilkan semua postingan
Jumat, 22 Oktober 2010
Senin, 18 Oktober 2010
String Split with Some Delimiters and Remove Duplicate
in this tutorial, I Want To show how to split a String into tokens with some delimiters and remove duplicate. thus, the result is a unique tokens. I am using Java.
For example:
String input = "AAAA AAAA BBBB BBBB CCCC djgu";
the result should be: {AAAA, BBBB, digu, CCCC}
The following is the complete source code:
String s2 = "cahdt aaaa aaaa bbbbb ddddd";
List li = new ArrayList ();
StringTokenizer st = new StringTokenizer (s2 ,";&@! - ");
while (st.hasMoreTokens ()) {
String temp = st.nextToken ();
li.add (temp);
}
Set set2 = new HashSet <string> <string> (li);
String [] result2 = new String [set2.size ()];
set2.toArray (result2);
for (String s: result2) {
System.out.print (s + ",");
}
For example:
String input = "AAAA AAAA BBBB BBBB CCCC djgu";
the result should be: {AAAA, BBBB, digu, CCCC}
The following is the complete source code:
String s2 = "cahdt aaaa aaaa bbbbb ddddd";
List li = new ArrayList ();
StringTokenizer st = new StringTokenizer (s2 ,";&@! - ");
while (st.hasMoreTokens ()) {
String temp = st.nextToken ();
li.add (temp);
}
Set set2 = new HashSet <string> <string> (li);
String [] result2 = new String [set2.size ()];
set2.toArray (result2);
for (String s: result2) {
System.out.print (s + ",");
}
Java: How to Install GWT in Netbeans
Google Web Toolkit (GWT) is an open source web development framework that allows developers to easily create high-performance AJAX applications using Java. Google Web Toolkit is getting a lot of attention in the web developer community thanks to its interesting way of avoiding the need to write JavaScript code for interactive web applications. You can download this GWT plug-in here and start developing GWT-based applications in NetBeans.
With GWT, you are able to write your front end in Java, and it compiles your source code into highly optimized, browser-compliant JavaScript and HTML. "Writing web apps today is a tedious and error-prone process. You spend 90% of your time working around browser quirks, and JavaScript's lack of modularity makes sharing, testing, and reusing AJAX components difficult and fragile. It doesn't have to be that way," reads the Google Web Toolkit site.
In this tutorial, you learn how the above principles are applied to real applications. At the same time, you are introduced to NetBeans IDE's support for GWT and you build a simple application that makes use of some of these features.
1. Download GWT plugin here
2. Install the plug-in using the Plug-in manager. Go to the "Tools | Plugins" menu action, switch to the "Downloaded" tab and locate the plug-in on your disk drive.
You don't even have to restart your IDE - GWT support is instantly available for you!
Creating the Source Structure of a GWT Application
1. Choose File > New Project (Ctrl-Shift-N). Under Categories, select Web (or Java Web). Under Projects, select Web Application. Click Next.
2. In step 2, Name and Location, type HelloGWT in Project Name. You can also specify the location of the project by typing in a path on your computer in Project Location field. Click Next.
3. In the Server and Settings step, select any server that you have registered in the IDE. If you included Tomcat or the GlassFish server when installing the IDE, they display in the drop-down list.
4. Specify the Java version you are using. Click Next.
5. In the framework Step, select GWT:

6. click finish.
7. In the Projects window, right-click the project node and choose Run. The application is built and a web archive (WAR) is created. It is deployed to the server. The server starts, if it is not running already. Your computer's default browser opens and the welcome page of the application is displayed.
source : http://netbeans.org/kb/docs/web/quickstart-webapps-gwt.html
With GWT, you are able to write your front end in Java, and it compiles your source code into highly optimized, browser-compliant JavaScript and HTML. "Writing web apps today is a tedious and error-prone process. You spend 90% of your time working around browser quirks, and JavaScript's lack of modularity makes sharing, testing, and reusing AJAX components difficult and fragile. It doesn't have to be that way," reads the Google Web Toolkit site.
In this tutorial, you learn how the above principles are applied to real applications. At the same time, you are introduced to NetBeans IDE's support for GWT and you build a simple application that makes use of some of these features.
1. Download GWT plugin here
2. Install the plug-in using the Plug-in manager. Go to the "Tools | Plugins" menu action, switch to the "Downloaded" tab and locate the plug-in on your disk drive.
You don't even have to restart your IDE - GWT support is instantly available for you!
Creating the Source Structure of a GWT Application
1. Choose File > New Project (Ctrl-Shift-N). Under Categories, select Web (or Java Web). Under Projects, select Web Application. Click Next.
2. In step 2, Name and Location, type HelloGWT in Project Name. You can also specify the location of the project by typing in a path on your computer in Project Location field. Click Next.
3. In the Server and Settings step, select any server that you have registered in the IDE. If you included Tomcat or the GlassFish server when installing the IDE, they display in the drop-down list.
4. Specify the Java version you are using. Click Next.
5. In the framework Step, select GWT:

6. click finish.
7. In the Projects window, right-click the project node and choose Run. The application is built and a web archive (WAR) is created. It is deployed to the server. The server starts, if it is not running already. Your computer's default browser opens and the welcome page of the application is displayed.
source : http://netbeans.org/kb/docs/web/quickstart-webapps-gwt.html
Java: Arabict text encoding in Java and Mysql
I do not have a problem when retrieving arabic text data from mysql database. But when the input Arabic text into my database is having problems. Arabic text changed to "????", so it can not be read. after looking for a solution, I found a way to solve it.
First, the Arabic text should be encoded first by using the code:
StrToEncode String = "بسم الله";
String encoded = URLEncoder.encode (strToEncode, "UTF-8");
now, that has been encoded strToEncode changed to:
% D8% A8% D8% B3% D9% 85 +% D8% A7% D9% 84% D9% 84% D9% 87
encode the string that is inserted into the mysql. then to read the Arabic text data from mysql database needs to be decoded using the code:
String correctDecoded = URLDecoder.decode (encoded, "UTF-8");
and the results of correctDecode:
بسم الله
First, the Arabic text should be encoded first by using the code:
StrToEncode String = "بسم الله";
String encoded = URLEncoder.encode (strToEncode, "UTF-8");
now, that has been encoded strToEncode changed to:
% D8% A8% D8% B3% D9% 85 +% D8% A7% D9% 84% D9% 84% D9% 87
encode the string that is inserted into the mysql. then to read the Arabic text data from mysql database needs to be decoded using the code:
String correctDecoded = URLDecoder.decode (encoded, "UTF-8");
and the results of correctDecode:
بسم الله
Langganan:
Postingan (Atom)