Selasa, 30 Juni 2009

Creating JAR File (Java programming)

Dear Friends.
Today I will show you how to create an executable jar file. I do not know whether this topic is introduced by any other member. Using this method one can build graphical user interface program with java which will behave similar to Executable files i.e., the program can be started with double clicks. It is an easy alternative. Otherwise to run a java program one has to run it through comand prompt(in windows) using java command or by creating java executalbes which are very difficult to make. So lets begin:Frist of all, we will create a simple java application using java foundation class popularly known as java Swing. Let the file name be JarExample.


CODE
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class JarExample {
private static void createAndShowGUI() {
JFrame.setDefaultLookAndFeelDecorated(true);
JFrame frame = new JFrame("Window");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JLabel emptyLabel = new JLabel("");
emptyLabel.setPreferredSize(new Dimension(175, 100));
frame.getContentPane().add(emptyLabel, BorderLayout.CENTER);
frame.pack();
frame.setVisible(true);
}
public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}}


Now compile the java file .JDK
will produce two class files namely (a)JarExample.class ( JarExample$1.class.All the years we have been doing this.Your question might be what new? Its coming.Now we will create a Manifest File. If you have done java beans then you are quite familiar with the term.Let write our Manifest File:-The name of the file is :- jex.mf

CODE
Manifest-Version: 1.0
Main-Class: JarExample


We are now ready to create our JAR file.create a folder, keep the class files (JarExample.class,JarExample$1.class) and the manifest file in that folder.Now open command prompt. Say for example your folder name is jar and you have kept it in C DRIVE. Now change directory using CD jar command.
Now we will create jar file using following command.
c:\jar>jar cfm jarex.jar jex.mf *.class
It will create jarex.jar
I wish you will be able to create jar file using this method. If any problem occur feel free to ask me or you have any suggestion please tell me.

Senin, 29 Juni 2009

PHP Redirect

You can use a simple PHP script to redirect a user from the page they entered to a different web page. One reason you may want to do this is that the page they are trying to access no longer exists. Using this method, they can be seamlessly transfered to the new page without having to click a link to continue.

//this will NOT work, the browser received the HTML tag before the script
header( 'Location: http://www.yoursite.com/new_page.html' );
?>

FTP Transfer with PHP

$ftp_server = "192.168.x.x";
$ftp_user = "user";
$ftp_pass = "pass";

$conn_id = ftp_connect($ftp_server) or die("Couldn't connect to ftp server");
if (@ftp_login($conn_id, $ftp_user, $ftp_pass)) {
echo "Connected as ftp://ftp.test.co.id/n";
} else {
echo "Couldn't connect as ftp user\n";
}

$dir_upload = "ftp://user:pass@192.168.x.x/";
$nama_file = $_POST['loc'].' - '.$_FILES['file']['name'];
if(is_uploaded_file($_FILES['file']['tmp_name']))
{
$cek = move_uploaded_file($_FILES['file']['tmp_name'],$dir_upload.$nama_file);
if($cek) {
echo 'File uploaded!';
} else {
echo ' ** Failure! **';
}
} ftp_close($conn_id);

FTP Transfer with PHP

$ftp_server = "192.168.x.x";

$ftp_user = "user";

$ftp_pass = "pass";


$conn_id = ftp_connect($ftp_server) or die("Couldn't connect to ftp server");

if (@ftp_login($conn_id, $ftp_user, $ftp_pass)) {

echo "Connected as ftp.gmf-aeroasia.co.id\n";

} else {

echo "Couldn't connect as ftp user\n";

}



$nama_file = $_POST['loc'].' - '.$_FILES['file']['name'];

if(is_uploaded_file($_FILES['file']['tmp_name']))

{

$cek = move_uploaded_file($_FILES['file']['tmp_name'],$dir_upload.$nama_file);

if($cek)

{ echo 'File uploaded!
';

} else {

echo ' ** Failure! **
';

}

} ftp_close($conn_id);

}

Procedure dan Function

Syntax Umum
procedure
Syntak untuk membuat procedure dalam MySQL adalah sebagai berikut.

CREATE [DEFINER = { user CURRENT_USER }] PROCEDURE sp_name ([proc_parameter[,...]]) [characteristic ...] routine_body

Function

CREATE [DEFINER = { user CURRENT_USER }] FUNCTION sp_name ([func_parameter[,...]]) RETURNS type [characteristic ...] routine_body

Example

mysql> delimiter //
mysql> CREATE PROCEDURE jumlahSiswa (OUT param1 INT)
-> BEGIN
-> SELECT COUNT(*) INTO param1 FROM siswa;
-> END;
-> //

Query OK, 0 rows affected (0.00 sec)mysql> delimiter ;

Example Lock Table MySQL

LOCK TABLES `daftar` WRITE;
INSERT INTO `daftar` VALUES ('','yoyo','tangerang','19-01-1986','123','yupe','kisamaun','0856','1','ipa','10');
UNLOCK TABLES;

Example Lock Table MySQL

LOCK TABLES `daftar` WRITE;

INSERT INTO `daftar` VALUES ('','yoyo','tangerang','19-01-1986','123','yupe','kisamaun','0856','1','ipa','10');

UNLOCK TABLES;

Example Lock Table MySQL

LOCK TABLES `daftar` WRITE;

INSERT INTO `daftar` VALUES ('','yoyo','tangerang','19-01-1986','123','yupe','kisamaun','0856','1','ipa','10');

UNLOCK TABLES;

Selasa, 23 Juni 2009

Sample command prompt with PHP

$temp = '';
$last_line = system("DEL /Q C:\TW.txt");
$temp .= ''.'';

OUTPUT Console is : DEL /Q C:\TW.txt

Connection MySQL

Simple Connection MySql

include('adodb/adodb.inc.php');
$mySql = &ADONewConnection('mysql');
$mySql->Connect('192.168.x.x','root','pass','db');

Senin, 22 Juni 2009

SAP Connection

$usersap = "user";
$mandt = "300";
$login = array (
"ASHOST"=>"192.168.x.x",
"SYSNR"=>"00",
"CLIENT"=>"$mandt",
"USER"=>"$usersap",
"PASSWD"=>"xxx",
"LANG"=>"EN",
"CODEPAGE"=>"1100");
$rfc = saprfc_open($login);
if (! $rfc ) { echo "RFC connection failed"; exit; }

Flex Basic