[android-beginners] Re: connecting to a remote database tutorial/example?
hi jbrohan, I am new in android as well as no java programming experienced. I had tried the example provided here. however, it doesnt work for me as it just return "error". Can you provide me some guidance? On Oct 25, 3:29 am, jbrohan wrote: > Hello > I need to look up a database in my app. I'll be doing it next week I > expect. For the moment the php just returns a constant. > $do = $_REQUEST['do']; > if ($do == "groupphone"){ > $phone=trim($_REQUEST['phone']); > $phone=str_replace(array('.','(',')','-',' ','+'),'',$phone); > if (substr($phone,0,1) == '1') $phone = substr($phone,1); // remove > '1' > echo "error"; // initial testing}elseif($do == "startgroup"){ > > echo "xyz"; > ... > > the java that does the call to the php program on the server is... > > public String callWebPage(String URLstring, String parameters){ > String s; > try { > URL updateURL = new URL(URLstring+parameters); > URLConnection conn = updateURL.openConnection(); > InputStream is = conn.getInputStream(); > BufferedInputStream bis = new BufferedInputStream(is); > ByteArrayBuffer baf = new ByteArrayBuffer(50); > Log.e("SettingsDialog", "after the call to web"); > int current = 0; > while((current = bis.read()) != -1){ > baf.append((byte)current); > } > Log.e("SettingsDialog", "back from web page"+parameters); > /* Convert the Bytes read to a String. */ > s = new String(baf.toByteArray()); > Log.e("SettingsDialog", String.format("in callWebPage = > %s ",s)); > return s; > } catch (Exception e) { > Log.e("SettingsDialog", "exception in callWebPage"); > } > return "error"; > } > > And the setup of the URLstring is...s = callWebPage(Constants.WebCall, > "?do=groupphone&phone="+s); what the php script echoed is in s. > > It seems to be very reliable. > It's worthwhile running your script from a browser first to make sure > that it works. > > Good Luck > John > > On Oct 24, 11:21 am, gmseed wrote: > > > Hi > > > I'm developing an application to connect to a database on my website. > > > Does anyone know of a link to an example/tutorial in which this kind > > of operation is performed? > > > Thanks > > > Graham -- You received this message because you are subscribed to the Google Groups "Android Beginners" group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en
[android-beginners] Re: connecting to a remote database tutorial/example?
Hi Again I came across the following link: http://forums.devshed.com/java-help-9/jdbc-connecting-to-web-database-647416.html which discusses connecting to a remote database using JDBC, with the author noting that remote access had to be enabled with his web hoster. Cheers Graham On 26 Oct, 13:43, gmseed wrote: > Hi > > Thanks for explaining how you connect. I too use PHP, so I'll give it > a go. > > I was wondering if anyone had seen an example of using the URI > connection string in connecting to a database such as MySQL an using > Java's JDBC. That way, connecting direct to the database. > > Cheers > > Graham > > On 25 Oct, 11:29, jbrohan wrote: > > > Hello > > I need to look up a database in my app. I'll be doing it next week I > > expect. For the moment the php just returns a constant. > > > $do = $_REQUEST['do']; > > if ($do == "groupphone"){ > > $phone=trim($_REQUEST['phone']); > > $phone=str_replace(array('.','(',')','-',' ','+'),'',$phone); > > if (substr($phone,0,1) == '1') $phone = substr($phone,1); // remove > > '1' > > echo "error"; // initial testing}elseif($do == "startgroup"){ > > > echo "xyz"; > > ... > > > the java that does the call to the php program on the server is... > > > public String callWebPage(String URLstring, String parameters){ > > String s; > > try { > > URL updateURL = new URL(URLstring+parameters); > > URLConnection conn = updateURL.openConnection(); > > InputStream is = conn.getInputStream(); > > BufferedInputStream bis = new BufferedInputStream(is); > > ByteArrayBuffer baf = new ByteArrayBuffer(50); > > Log.e("SettingsDialog", "after the call to web"); > > int current = 0; > > while((current = bis.read()) != -1){ > > baf.append((byte)current); > > } > > Log.e("SettingsDialog", "back from web page"+parameters); > > /* Convert the Bytes read to a String. */ > > s = new String(baf.toByteArray()); > > Log.e("SettingsDialog", String.format("in callWebPage = > > %s ",s)); > > return s; > > } catch (Exception e) { > > Log.e("SettingsDialog", "exception in callWebPage"); > > } > > return "error"; > > } > > > And the setup of the URLstring is...s = callWebPage(Constants.WebCall, > > "?do=groupphone&phone="+s); what the php script echoed is in s. > > > It seems to be very reliable. > > It's worthwhile running your script from a browser first to make sure > > that it works. > > > Good Luck > > John > > > On Oct 24, 11:21 am, gmseed wrote: > > > > Hi > > > > I'm developing an application to connect to a database on my website. > > > > Does anyone know of a link to an example/tutorial in which this kind > > > of operation is performed? > > > > Thanks > > > > Graham --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Android Beginners" group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] Re: connecting to a remote database tutorial/example?
Hi Thanks for explaining how you connect. I too use PHP, so I'll give it a go. I was wondering if anyone had seen an example of using the URI connection string in connecting to a database such as MySQL an using Java's JDBC. That way, connecting direct to the database. Cheers Graham On 25 Oct, 11:29, jbrohan wrote: > Hello > I need to look up a database in my app. I'll be doing it next week I > expect. For the moment the php just returns a constant. > $do = $_REQUEST['do']; > if ($do == "groupphone"){ > $phone=trim($_REQUEST['phone']); > $phone=str_replace(array('.','(',')','-',' ','+'),'',$phone); > if (substr($phone,0,1) == '1') $phone = substr($phone,1); // remove > '1' > echo "error"; // initial testing}elseif($do == "startgroup"){ > > echo "xyz"; > ... > > the java that does the call to the php program on the server is... > > public String callWebPage(String URLstring, String parameters){ > String s; > try { > URL updateURL = new URL(URLstring+parameters); > URLConnection conn = updateURL.openConnection(); > InputStream is = conn.getInputStream(); > BufferedInputStream bis = new BufferedInputStream(is); > ByteArrayBuffer baf = new ByteArrayBuffer(50); > Log.e("SettingsDialog", "after the call to web"); > int current = 0; > while((current = bis.read()) != -1){ > baf.append((byte)current); > } > Log.e("SettingsDialog", "back from web page"+parameters); > /* Convert the Bytes read to a String. */ > s = new String(baf.toByteArray()); > Log.e("SettingsDialog", String.format("in callWebPage = > %s ",s)); > return s; > } catch (Exception e) { > Log.e("SettingsDialog", "exception in callWebPage"); > } > return "error"; > } > > And the setup of the URLstring is...s = callWebPage(Constants.WebCall, > "?do=groupphone&phone="+s); what the php script echoed is in s. > > It seems to be very reliable. > It's worthwhile running your script from a browser first to make sure > that it works. > > Good Luck > John > > On Oct 24, 11:21 am, gmseed wrote: > > > Hi > > > I'm developing an application to connect to a database on my website. > > > Does anyone know of a link to an example/tutorial in which this kind > > of operation is performed? > > > Thanks > > > Graham --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Android Beginners" group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] Re: connecting to a remote database tutorial/example?
Hello I need to look up a database in my app. I'll be doing it next week I expect. For the moment the php just returns a constant. wrote: > Hi > > I'm developing an application to connect to a database on my website. > > Does anyone know of a link to an example/tutorial in which this kind > of operation is performed? > > Thanks > > Graham --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Android Beginners" group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] Re: connecting to a remote database tutorial/example?
I have never tried connecting to a hosted DB within android app. maybe you should consider using a webservice either SOAP or RESTful. On Sat, Oct 24, 2009 at 11:21 AM, gmseed wrote: > > Hi > > I'm developing an application to connect to a database on my website. > > Does anyone know of a link to an example/tutorial in which this kind > of operation is performed? > > Thanks > > Graham > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Android Beginners" group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---