If you are using Internet Explorer, please remove blackberry.com from your compatibility view settings.

Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
New Contributor
chanfui
Posts: 8
Registered: ‎07-03-2010
My Device: Curve
My Carrier: Whatever

Re: java application connected to a Mysql server

Since everyone is talking 'pseudo code' but not real technical example source codes makes you keep questioning the same question.

 

Here's the link that explain the way to connect mySQL database through PHP site by using BlackBerry device,  hope it might help you to get your answer.

 

The link: http://www.blackberryforums.com.au/forums/third-party-applications/4682-how-connect-database.html

Please use plain text.
Developer
peter_strange
Posts: 19,601
Registered: ‎07-14-2008
My Device: Not Specified

Re: java application connected to a Mysql server

That looks a useful link, however I can't download the indicated pdf.  I imagine other people will not be able to either.  Do you have a copy?  If so, perhaps I can attach it to this post?

Please use plain text.
New Contributor
chanfui
Posts: 8
Registered: ‎07-03-2010
My Device: Curve
My Carrier: Whatever

Re: java application connected to a Mysql server

What you need to get the file is just register as a member at the forum website. After verify your account via email, you can download from the given link, simple as mentioned.

Please use plain text.
Developer
peter_strange
Posts: 19,601
Registered: ‎07-14-2008
My Device: Not Specified

Re: java application connected to a Mysql server

Attached is the pdf and associated source.

 

I have only very briefly reviewed this, however it looks a good introduction to using mySQL via PHP on BlackBerry devices. 

 

 

Please use plain text.
Contributor
pavanhemdev
Posts: 13
Registered: ‎11-21-2010
My Device: Not Specified

Re: java application connected to a Mysql server

 

 

Hi Guys,

 

 

Thanks for everything. 

 I seem to be getting a response Code of 400.

 

Im a beginner here, can someone please explain what i could have possible done wrong.

 

Ive attached my files..

 

 

 

/*
 * Retrieving.java
 *
 * © Hemdev & Co, 2010
 * Confidential and proprietary.
 */

package com.beginningblackberry.indiaphonebook;

import net.rim.blackberry.api.browser.URLEncodedPostData;
import java.io.InputStream;
import java.io.InputStreamReader;
import javax.microedition.io.HttpConnection;
import javax.microedition.io.Connector;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.component.Dialog;

class Retrieving extends MainScreen{
    
    
    Retrieving() {
        
    }
    
    public static boolean retrieveResults(String selection, String selectedLocality, String searchName){
      boolean ret = false;
      // some variables necessary for HTTP communication
        InputStream inputStream = null;
        HttpConnection httpConnection = null;


        // because many of the steps can throw an exception, wrap this method in a try/catch block
        try
        {
            
            StringBuffer returnStringBuffer = new StringBuffer();
            String returnString = new String();
            

            String desiredEncoding = "ISO-8859-1";


            URLEncodedPostData params = new URLEncodedPostData(URLEncodedPostData.DEFAULT_CHARSET, true);
            params.append("name", searchName);
            
            
            String url = "http://pavanhemdev.bytehost31.com/searchrecords.php?" + params.toString();
                                   
            System.out.println(url);
                                       
                                       
            //Connecting to Server
            httpConnection = (HttpConnection)Connector.open(url);
            inputStream = httpConnection.openDataInputStream();
            int rc = httpConnection.getResponseCode();
            System.out.println("THE RC IS:"+ rc);
            if(rc == HttpConnection.HTTP_OK)
            {
                int ch;
                
                //Process Response
                
                // check header field for a specific encoding
                String contenttype = httpConnection.getHeaderField("Content-Type");
                if (contenttype != null)
                {
                    contenttype = contenttype.toUpperCase();
                    if (contenttype.indexOf("UTF-8") != -1)
                    {
                        desiredEncoding = "UTF-8";
                    }
                }
            
                // get an inputstreamreader to handle utf-8 data
                InputStreamReader isr = new InputStreamReader(inputStream,desiredEncoding);
            
                while ((ch = isr.read()) != -1) 
                {
                    returnStringBuffer.append((char) ch);
                }
                    
                inputStream.close();
                httpConnection.close();
                inputStream = null;
                httpConnection = null;
                returnString = returnStringBuffer.toString();

                // examine return string
                if (returnString.indexOf("SUCCESS") != -1)
                {
                    ret = true;
                }
                return ret;
            }
            inputStream.close();
            httpConnection.close();
            inputStream = null;
            httpConnection = null;
            //Bad Transaction.
            return ret;
        }
        catch (Exception e)
        {
            System.out.println("Error occurred in ProcessTransaction()\n" + e.toString());
            return ret;
        }
        finally
        {
            try
            {
                if (inputStream != null)
                    inputStream.close();
                if (httpConnection != null)
                    httpConnection.close();
            }
            catch (Exception ee)
            {
            }
        }
         
    }
   
} 

 

 

 

 

<?php
$user="*******";
$password="******";
$hostname = "sql103.byethost31.com";
$database="********";
$conn=mysql_connect($hostname,$user,$password); // if you are going to use multiple connections its worth using a var as a connection to call so becomes easy to use like this mysql_query($sql,$conn) or mysql_query($sql,$conn3)
$conn or die("unable to connect to host");
@mysql_select_db($database) or die( "Unable to select database");

$sql ="insert into temp values ('Sigdi','00912224865413','556464674353','34394113','cewjygwech'.'ecgecvjecv','ckgeivho','cievbikb','dckvgvh','htfujvbib')";
$result= mysql_query($sql,$conn);
if(result==1)
{
print("SUCCESS");
}
else
{
print("FAILED");
}
?>

 

 

Please use plain text.
Developer
peter_strange
Posts: 19,601
Registered: ‎07-14-2008
My Device: Not Specified

Re: java application connected to a Mysql server

400 usually indicates a Server error.  I would try the same URL from the Browser and make sure that you can access it.  I wold also check the Server logs to see if you can see anything in there related.  Also can you check the connection suffix you are using?

Please use plain text.
Contributor
pavanhemdev
Posts: 13
Registered: ‎11-21-2010
My Device: Not Specified

Re: java application connected to a Mysql server

Hi Peter, Thanks for that.. A silly typo in the url made me go crazy in the head.. apologies.. The correct URL is - http://pavanhemdev.byethost31.com/searchrecords.php? However, I now get a Response code of 403. I checked the .htaccess file and it is currently blank I've done chmod to 755. Am i missing something?
Please use plain text.