jeudi 13 août 2015

Establish connection between app server and oracle database using java

I have been given a task to write a script in java, to connect oracle database from an app server. Scheduling tool will be used to schedule the job every 10 minutes.

If connection exists, the script will do nothing and just disconnect it. (and will be run again after 10 minutes). If cannot connect after 10 secs, the program will send an email notification.

The whole thing is to ensure connection can be established between the app server and the oracle db.

Really have no clue on this. Could you please advise what are the steps to do this and what Java APIs I'll need??

Many many thanks in advance!



via Chebli Mohamed

Full screen mode in java application

I would like to make an app that have a button that make the app full screen when clicked and then change to normal when the button is clicked second time. The JDK is 1.7 and I know it support application in full screen mode. I tried in many ways but not succeed. Please, is there someone who could help me?



via Chebli Mohamed

DateFormat return null java

I'm confused. I've tried, well I can not assign a null value to projects which have no date. What am i doing wrong?

 private static String projectDate = null;
    public static void main(String[] args) throws Exception {
        DateFormat formatter = new SimpleDateFormat("dd.MM.yyyy");
            List<Project> projects;
            if (projects == null || projects.size() == 0) {
            } else {
                for (Project project : projects) {
                    try {
                        projectDate = formatter.format(project.getLastAnalyzedDate().getTime());
                    }catch (Exception e) {
                        System.err.println("Last Analyzed failed");
                    }
                    outFile.println("<LastAnalyzed>" + projectDate + "</LastAnalyzed>");



via Chebli Mohamed

Simple upload to S3 from android

I've searched the web for ways to upload a simple file to s3 from android but couldn't find anything that work and I think it is because lack of concrete steps.

1.) http://ift.tt/1PaB2FW

That is the best guide I found but it does not tell what libraries to include. I downloaded the aws sdk for android and inside there were many jars. So intuitively, I included the aws-android-sdk-s3-2.2.5.jar however that is not complete. It does not have the class BasicAWSCredentials.

2.)I've looked at the more at the sample but it is not straightforward as #1 and I couldn't get the core upload functionality with credentials.

I appreciate your help



via Chebli Mohamed

Crosswalk project how to keep view alive

My app works with regular webview but it's very slow under Android 4.0 - 4.2 and just slow on 4.3 and 4.4.

I've already done lot of optimalizations in html/js/css, but still is too slow. So decided to take a look at Crosswalk project.

It's almost all great even with +20mb size for apk, except for one thing..

You cannot create XWalkView (equivalent of WebView) with Service context (like you can do with regular WebView) only Activity context is an option for Crosswalk view.

Why it's bad?

The website that I load into WebView/XWalkView uses WebSockets, it has to be always alive! But Android likes to kill apps, especially on older devices with Android 4.0-4.2.

Solution is to create WebView with Service context and keep reference to it in Service (Service is in foreground mode so hard to kill!).

Then if Activity will crash or will be garbage-collected, simply user taps to it, Activity recreates himself and gets reference to WebView (from Service class) to add it to his hierarchy again. :) (and in the meantime when activity didn't exist, webview was still working along with websocket connection)

All works, but with WebView and WebView is slow..

Why I am writing it? Need advice from you what to do or maybe solution how to force CrossWalk view to works with Service context.

Is it other way to keep XWalkView "always" alive?

Thanks!



via Chebli Mohamed

Java: PrintWriter object does not output the text on my file?

I'm trying to print out the usernames of a certain program into a file but PrintWriter is not printing anything on my file. I've tried everything mentioned on stackOverFlow none of them worked.

Users Class

private File usersListFile;
private PrintWriter usersListPrintWriter;
private Scanner usersListScanner;

Constructor:

Users(){
    try {
        this.usersListFile = new File("D:\\Dairy\\usersList.txt");
        if(usersListFile.exists()){
            this.usersListPrintWriter = new PrintWriter(new BufferedWriter(new FileWriter("D:\\Dairy\\usersList.txt", true)));
            this.usersListScanner = new Scanner("D:\\Dairy\\usersList.txt");
        }
        else
            System.err.println("File does not exist !");
    }
    catch(Exception e){
        System.err.println("Error: Users Class!");                   
    }
}

Method:

public void addToUsersList(String username){
        usersListPrintWriter.print(username);           
    }

Main Method:

public static void main(String[] args) {

    Users usersObject = new Users();
    usersObject.addToUsersList("USERNAME");

    }



via Chebli Mohamed

Android eclipse xml formatting issue

Hello i have a xml file which doesent seem to work, i am trying to reach it with a listpreference.

Here is the listpreference code:

<PreferenceCategory android:name="@string/yo_category">

<ListPreference
    android:title="YOYO"
    android:key="YOYOYO"
    android:summary="YODOBO"
    android:entries="@+arrays/yoyo"
    android:entryValues="@+arrays/yoyoValues"
></ListPreference>

</PreferenceCategory>  

And here is the xml file:

<string-array name="yoyo">
    <item>1 yoyo</item>
    <item>2 yoyos</item>
    <item>3 yoyos</item>
</string-array>
<string-array name="yoyoValues">
    <item>1</item>
    <item>2</item>
    <item>3</item>
</string-array>

PreferenceActivity class:

public class PreferenceHandler extends PreferenceActivity

@Override
protected void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);

    getFragmentManager().beginTransaction().replace(android.R.id.content, new PrefFragment()).commit();
}

public static class PrefFragment extends PreferenceFragment
{
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);

        addPreferencesFromResource(R.xml.preferences);
}
}   

} And i cannot seem to find the issue here, i get no errors in eclipse but when i try to run it i cant see the items in the listpreference.

Thanks for any help!



via Chebli Mohamed