How to manage annotation based Hibernate versioning for time stamp column in which value generated by DB

We can generate version column’s value by using below tag in our hbm file <timestamp column="MODIFICATION_DATE" name="modificationDate" access="property" unsaved-value="undefined" source="db" generated="always"/>

What is the corresponding hibernate notation to generate value for time stamp column which date type

private java.util.Date modificationDate;

Java – Oracle Weblogic 12c – Eclipse . I can’t seem to get the proper path to connect my db file located in the resource folder

My program structure. myApp -> src -> database -> myApp.db

String DB_LOCATION = "myApp/src/database/myApp.db";
conn = DriverManager.getConnection("jdbc:sqlite:"+ DB_LOCATION);

This is the Console output

java.sql.SQLException: path to ‘myApp/src/database/myApp.db’: ‘C:OracleMiddlewareOracle_Homeuser_projectsdomainsbase_domainmyApp’ does not exist

I want to not point to the server path as i am going to deploy to another server.

What can i do?

How to convert a 2D Int array to a string

Trying to create a basic battleships game

   import java.util.*;
   import java.util.Scanner;
   public class BattleShip
   {
      Scanner input = new Scanner(System.in);
      //public static final boolean DEBUG = false;
      public static void breakln()
      {

   }


      public static void main(String[] arg)
      {
          int size = 0;   
          int[][] board = new int[5][5];
         createBoard(board);
         createShip(board, 4);
         BattleShip.createBoard(board);
         BattleShip.Display_Baord(board);
         BattleShip.createShip(board, size );

      }



      public static void createBoard(int[][] board){
          for(int row=0 ; row < 5 ; row++ )
              for(int column=0 ; column < 5 ; column++ )
                  board[row][column]=-1;
      }

      public static void Display_Baord(int[][] board){
          System.out.println("t1 t2 t3 t4 t5");
          System.out.println

();

          for(int row=0 ; row < 5 ; row++ ){
              System.out.print((row+1)+"");
              for(int column=0 ; column < 5 ; column++ ){
                  if(board[row][column]==-1){
                      System.out.print("t"+"~");
                  }else if(board[row][column]==0){
                      System.out.print("t"+"*");
                  }else if(board[row][column]==1){
                      System.out.print("t"+"X");
                  }

              }
              System.out.println();
          }

      }



      This is the method where the error is 

      public static void createShip(int[][] board,int size)
      {
         if(Math.random() < 0.5)
         {
            int col = (int)(Math.random()*5);
            int row = (int)(Math.random()*7);
            for(int i = 0; i<size; i++)
            {
               board[row][col+i] = "S"; Hear is my error, i cannot have 's' as my 2d array ' board is an int
            }
         }
         else
         {
            int col = (int)(Math.random()*7);
            int row = (int)(Math.random()*5);
            for(int i = 0; i<size; i++)
            {
               board[row+i][col] = "S";    Hear is my error, it cannot be a string as 'board' is an int 
            }
         }
      }
   }

I’m just looking to find out how I can store ‘s’ in my int 2D array Board.

Thanks in advance

ggggggggggggggggggggggggggggggggggggggggggggggggvggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggvgggggggggggg

Anyone have/know of any java SMTP client/server example code?

I’m trying to learn about smtp server and clients so that i can build both the client and server parts however i can’t really find any examples of a working set, only finding the client code. I understand the individual parts but not how to proplerly put it together and seeing a working example would be awesome and so helpful.

Thanks to anyone who can help me out!

Scanner issue! Code is skipping the first user input and printing twice instead of once ONLY on the first iteration.

https://courses.cs.washington.edu/courses/cse142/15sp/homework/6/spec.pdf

Hello, I have a question about scanners because I don’t understand why the code
is skipping the user input on the first iteration but works fine on the rest.
I’m writing a code to create a madlib program and the link will provide the explanation to the program but pretty much you have these placeholders in a text file and when you see one, you prompt for user input to replace it with your own words. However, my program always go through TWO placeholders first and only ask the user input for one, completely skipping the first placeholder. What is wrong with my code??? Also, how do you fix this? Everything else is running perfectly fine, only that the first line is consuming two placeholders so I’m always off by one.

Welcome to the game of Mad Libs.
I will ask you to provide various words

and phrases to fill in a story.

The result will be written to an output file.

(C)reate mad-lib, (V)iew mad-lib, (Q)uit? c

Input file name: tarzan.txt

Output file name: test.txt

Please type an adjective: Please type a plural noun: DD DDDD <— why is it like this

Please type a noun: DDDD

Please type an adjective: DD

Please type a place:



========================================================================

package MadLibs;
import java.util.*;
import java.io.*;

public class MadLibs2 {
   public static void main(String[] args) throws FileNotFoundException {
      Scanner console = new Scanner(System.in);
      intro();
      boolean isTrue = true;
      while(isTrue) {
          System.out.print("(C)reate mad-lib, (V)iew mad-lib, (Q)uit? ");
          String choice = console.next();
         if (choice.equalsIgnoreCase("c")) {
            create(console);
         } 
         else if (choice.equalsIgnoreCase("v")) {
            view(console);
         } 
         else if (choice.equalsIgnoreCase("q")) {
            System.exit(0);
         }  
      }
   }

   public static void view(Scanner console) throws FileNotFoundException {
       System.out.print("Input file name: ");
       String viewFile = console.next();
       File existingMadLib = new File(viewFile);
       Scanner printText = new Scanner(existingMadLib);
       while(printText.hasNextLine()) {
           System.out.println(printText.nextLine());
       }
   }

   public static void create(Scanner console) throws FileNotFoundException {
      System.out.print("Input file name: ");
      String inputFile = console.next();
      File newMadLib = new File(inputFile);
      while(!newMadLib.exists()) {
         System.out.print("File not found. Try again: ");
         inputFile = console.next();
         newMadLib = new File(inputFile);
      }
      System.out.print("Output file name: ");
      String outputFile = console.next();
      System.out.println();
      PrintStream output = new PrintStream(new File(outputFile));
      Scanner input = new Scanner(newMadLib); 
      while(input.hasNextLine()) {
         String line = input.nextLine();
         outputLines(line, output, console);
      }
   }

   public static void outputLines(String line, PrintStream output, Scanner console) throws FileNotFoundException{
      String s = "";
      Scanner lineScan = new Scanner(line);
      while(lineScan.hasNext()){
         s = lineScan.next();
         if(s.startsWith("<") || s.endsWith(">")) {
            s = rePlaceholder(console, lineScan, s);
         }
         output.print(s + " ");
      }
      output.println();
   }

   public static String rePlaceholder(Scanner console, Scanner input, String token) {           
      String placeholder = token;
      placeholder = placeholder.replace("<", "").replace(">", "").replace("-",  " ");
      if (placeholder.startsWith("a") || placeholder.startsWith("e") || placeholder.startsWith("i") 
       || placeholder.startsWith("o") || placeholder.startsWith("u")) {
         System.out.print("Please type an " + placeholder + ": ");
      }  else {
          System.out.print("Please type a " + placeholder + ": ");
       }
      String change = console.nextLine();
      return change;
   }

   public static void intro() {
      System.out.println("Welcome to the game of Mad Libs.");
      System.out.println("I will ask you to provide various words");
      System.out.println("and phrases to fill in a story.");
      System.out.println("The result will be written to an output file.");
   }
}

Android – Select website and its language in AlertDialog and save it

I need to load and save a website and its language in sharedpreferences. When I exit and then open the app, saved website and language load. I have used various ways, but cant achieve it. There is String and int not compatible with each other. My simple code like this:

      private SharedPreferences prefs;
      private static final String SELECTED_ITEM = "SelectedItem";
      private SharedPreferences.Editor sharedPrefEditor;

  @SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
    // Handle navigation view item clicks here.
    int id = item.getItemId();

    else if (id == R.id.web) 
    final CharSequence[] items={"English","Arabic","Russian"};

        AlertDialog.Builder builder = new AlertDialog.Builder(
                MainActivity.this);

        builder.setTitle("Choose Website");
        builder.setPositiveButton("ok", new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {}
        });

        builder.setSingleChoiceItems(items, getSelectedItem(), new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                // TODO Auto-generated method stub
                webView = (WebView) findViewById(R.id.webView);
                int website=current_page;

                if("English".equals(items[which]))
                {
                    webView.loadUrl("https://english.com");
                    website=("https://english.com");
                }
                else if("Arabic".equals(items[which]))
                {
                    webView.loadUrl("https://arabic.com");
                    website=("https://arabic.com");
                }
                else if("Russian".equals(items[which]))
                {
                    webView.loadUrl("https://russian.com");
                    website=("https://russian.com");
                }

                saveSelectedItem(website);
            }
        });
        builder.show();
    }

 private int getSelectedItem() {
      if (prefs == null) {
        prefs = PreferenceManager
                .getDefaultSharedPreferences(this);
    }
    return prefs.getInt(SELECTED_ITEM, -1);
}

  private void saveSelectedItem(int which) {
    if (prefs == null) {
        prefs = PreferenceManager
                .getDefaultSharedPreferences(this);
    }
    sharedPrefEditor = prefs.edit();
    sharedPrefEditor.putInt(SELECTED_ITEM, which);
    sharedPrefEditor.commit();
}

sending image dataUri using jQuery ajax post request and getting null when reading image data in servlet using request parameter

I have the image data url/blob and is trying jQuery ajax post request.
Getting null when reading image data as request parameter.

MyJsCode:

var dataURL = canvas.to DataURL('image/jpeg',0.5);
var blob = dataURItoBlob(dataURL);
canvas.toBlob(
function(blob){
var fd = new FormData();
fd.append("myFile",blob, "image.jpg");
jQuery.ajax({
url:"app/service",
type:"post",
data:fd,
processData:false,
contentType:false,
success:function(){}
});
},'image/jpeg',0.8

);

MyServlet: using SlingHttpServletRequest request

request.getParameter("myFile"): // gives me null

Do we know if there is something wrong with ajax call or i am trying to request a different parameter or there is other way of doing it in Adobe AEM.

Bean Validation on XML Element Choice

How do I add bean validation specifically for a String.class type element within a choice:

    @NotNull(message = "ContactUser or CompanyName is required.")
    @Valid
    @XmlElements(value = {
        @XmlElement(name = "ContactUser", type = ContactUser.class, required = true),
        @XmlElement(name = "CompanyName", type = String.class, required = true) })
private Object contactInfo;

(This is from reading article: http://blog.bdoughan.com/2010/10/jaxb-and-xsd-choice-xmlelements.html)
@Valid works to turn on validation for ContactUser.class and @NotNull works because contactInfo is of type Object. When I try to add

@Size(min = 10, max = 16)

Above the code, it gives me the following error:

javax.validation.UnexpectedTypeException: HV000030: No validator could be found for type: java.lang.Object.

I am guessing this is because of the type of contactInfo?