Monday, 20 January 2014

Replace First Occurrence of string in SQL Server


declare @str     varchar(1000),
  @searchString    varchar(100),
  @replaceString varchar(100)

select  @str   = ProductID in
 '(Select ChildProductid  from ProductBreakup where ProductID=111 )',
  @searchString    = 'ProductID ',
  @replaceString = 'l.ProductID'

select  @str,
 stuff(@str, charindex(@searchString    , @str), len(@searchString    ), @replaceString )

Wednesday, 18 September 2013

Backup and Restore of mysql database using java

 

Backup of database

For windows

String[] command = new String[]{"cmd.exe", "/c", "mysqldump --host=localhost --user=root --opt --password=admin dbname > backup.sql"};
                        Runtime.getRuntime().exec(command);

For Linux

 String[] command = new String[]{"sh", "-c", "mysqldump --host=localhost --user=root --opt --password=admin dbname > backup.sql"};
                        Runtime.getRuntime().exec(command);


Restore the database

For windows

String[] command = new String[]{"cmd.exe", "/c", "mysql --host=localhost --user root --password=admin   dbname< backup.sql"};
                        Runtime.getRuntime().exec(command);

For Linux

 String[] command = new String[]{"sh", "-c", "mysql --host=localhost --user root --password=admin   dbname< backup.sql"};
                        Runtime.getRuntime().exec(command);


Friday, 19 April 2013

Stage/Scene Close on ESCAPE key Event in Java FX

Close Event on Pressing ESCAPE in Java FX

For this you have to apply onkeyPressed Event on ESCAPE. Sample code as follows:

import javafx.application.Application;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.scene.text.Text;
import javafx.stage.Stage;

public class TableViewSample extends Application {

    public static void main(String[] args) {
    launch(args);
}

@Override
public void start(final Stage primaryStage) {
    primaryStage.setTitle("JavaFX Welcome");
    GridPane grid = new GridPane();
    grid.setAlignment(Pos.CENTER);
    grid.setHgap(10);
    grid.setVgap(10);
    grid.setPadding(new Insets(25, 25, 25, 25));

    Text scenetitle = new Text("Welcome");
    scenetitle.setId("welcome-text");
    grid.add(scenetitle, 0, 0, 2, 1);

    Label userName = new Label("User Name:");
    grid.add(userName, 0, 1);

    TextField userTextField = new TextField();
    grid.add(userTextField, 1, 1);

    Label pw = new Label("Password:");
    grid.add(pw, 0, 2);

    PasswordField pwBox = new PasswordField();
    grid.add(pwBox, 1, 2);

    Button btn = new Button("Sign in");
    HBox hbBtn = new HBox(10);
    hbBtn.setAlignment(Pos.BOTTOM_RIGHT);
    hbBtn.getChildren().add(btn);
    grid.add(hbBtn, 1, 4);

    Scene scene = new Scene(grid, 660, 300);
    scene.setOnKeyPressed(new EventHandler<KeyEvent>() {
        public void handle(KeyEvent ke) {
            if (ke.getCode() == KeyCode.ESCAPE) {
                System.out.println("Key Pressed: " + ke.getCode());
                primaryStage.close();
            }
        }
    });
    //primaryStage.setFullScreen(true);
    primaryStage.setScene(scene);
    primaryStage.show();
}
}

Wednesday, 3 April 2013

Decimal values TextField  In JavaFx

For decimal value text field in JavaFx use textfield event in this way

textField.addEventFilter(KeyEvent.KEY_TYPED,
                new EventHandler<KeyEvent>() {
                    public void handle(KeyEvent t) {
                        char ar[] = t.getCharacter().toCharArray();
                        char ch = ar[t.getCharacter().toCharArray().length - 1];
                        if (!((ch >= '0' && ch <= '9')|| ch=='.'))
                            t.consume();
                    }
                });

Saturday, 30 March 2013

Java Fx..........(Focus On a Particular Component)

  1. Java FX For this write code in your initialize Block of Scene
  2. public void initialize(URL arg0, ResourceBundle arg1) {
  3.         Platform.runLater(new Runnable() {
  4.             @Override
  5.             public void run() {
  6.             textBox.requestFocus();  
  7.             }
  8.         });
  9.     }

It place Focus on that particular (textBox) Component on Scene Load