<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-559085935872346632</id><updated>2024-10-04T19:41:37.156-07:00</updated><category term="android"/><category term="java"/><category term="socket programming"/><category term="android image transfer"/><category term="android java communication"/><category term="connection between java classes"/><category term="file transfer"/><category term="image transfer over socket"/><category term="java server"/><category term="socket. java"/><category term="android oracle connectivity"/><category term="android oracle connectivity thorugh java socket programming"/><category term="oracle"/><category term="oracle connectivity to java"/><category term="oracle-java"/><title type='text'>Android to Oracle connectivity through java</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://androracle.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/559085935872346632/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://androracle.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/10580831359890448769</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>4</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-559085935872346632.post-6004014784101432103</id><published>2012-08-02T13:49:00.000-07:00</published><updated>2012-08-02T13:59:58.710-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="android"/><category scheme="http://www.blogger.com/atom/ns#" term="android image transfer"/><category scheme="http://www.blogger.com/atom/ns#" term="android java communication"/><category scheme="http://www.blogger.com/atom/ns#" term="connection between java classes"/><category scheme="http://www.blogger.com/atom/ns#" term="file transfer"/><category scheme="http://www.blogger.com/atom/ns#" term="image transfer over socket"/><category scheme="http://www.blogger.com/atom/ns#" term="java"/><category scheme="http://www.blogger.com/atom/ns#" term="java server"/><category scheme="http://www.blogger.com/atom/ns#" term="socket programming"/><category scheme="http://www.blogger.com/atom/ns#" term="socket. java"/><title type='text'>Image Transfer to Android from Java over Sockets</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span style=&quot;font-family: Georgia, Utopia, &#39;Palatino Linotype&#39;, Palatino, serif; font-size: 15px; line-height: 21px; text-align: -webkit-auto;&quot;&gt;
Hello friends,&lt;br /&gt;
After my post about socket connection between android and java &lt;a href=&quot;http://androracle.blogspot.in/2012/07/client-side-programming-on-android.html&quot;&gt;&lt;b&gt;here&lt;/b&gt;&lt;/a&gt;, this post is all about file transfer or we can say image transfer between java and android. Here is same as my previous post where Java class is my server and android is client.&lt;br /&gt;
Here we are using a java class as server for android client is as follows.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Utopia, &#39;Palatino Linotype&#39;, Palatino, serif; font-size: 15px; line-height: 21px; text-align: -webkit-auto;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Utopia, &#39;Palatino Linotype&#39;, Palatino, serif; font-size: 15px; line-height: 21px; text-align: -webkit-auto;&quot;&gt;Server.java&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/div&gt;
&lt;div style=&quot;height: 500px; overflow: scroll;&quot;&gt;
&lt;table style=&quot;border: 1px solid;&quot;&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;br /&gt;
import java.net.*;&lt;br /&gt;
import java.io.*;&lt;br /&gt;
&lt;br /&gt;
import org.apache.commons.codec.binary.Base64;&lt;br /&gt;
&lt;br /&gt;
public class Server {&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;private static DataInputStream dataInputStream;&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;private static DataOutputStream dataOutputStream;&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;public static void main(String[] args) throws IOException {&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;// create socket&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;ServerSocket servsock = new ServerSocket(13267);&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; dataInputStream = new DataInputStream(sock.getInputStream());&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  d&lt;/span&gt;ataOutputStream = new DataOutputStream(sock.getOutputStream());&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;while (true) {&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;System.out.println(&quot;Waiting...&quot;);&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;Socket sock = servsock.accept();&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;System.out.println(&quot;Accepted connection : &quot; + sock);&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;File myFile = new File(&quot;F:\\ic_launcher.png&quot;);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;&lt;span style=&quot;text-align: left;&quot;&gt;System.out.println(&quot;Sending...&quot;);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;FileInputStream imageInFile = new FileInputStream(myFile);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;byte imageData[] = new byte[(int) myFile.length()];&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;imageInFile.read(imageData);&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;/*&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt; * Converting Image byte array into Base64 String&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt; */&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;String imageDataString = encodeImage(imageData);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;System.out.println(imageDataString.length());&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;System.out.println(imageDataString);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;dataOutputStream.writeUTF(imageDataString);&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;dataOutputStream.flush();&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;sock.close();&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;}&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;public static String encodeImage(byte[] imageByteArray) {&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;return Base64.encodeBase64String(imageByteArray);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;br /&gt;
}&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Utopia, &#39;Palatino Linotype&#39;, Palatino, serif; font-size: 15px; line-height: 21px; text-align: -webkit-auto;&quot;&gt;Here First I created a socket using ServerSocket class. 13267 is port number at which both the server and client going to communicate. You can change the port number but it must same for both the client and server. In this program I just read the image from my computer and then encode it into Base64 String. Now we will send this string to the client using DataOutputStrem.writeUTF(imageDataString) function. At the client side client will receive this string and then decode it into byte array. To encode image we need a jar file(&lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;commons-codec-1.6-bin&lt;/span&gt;&lt;span style=&quot;font-family: Georgia, Utopia, &#39;Palatino Linotype&#39;, Palatino, serif; font-size: 15px; line-height: 21px; text-align: -webkit-auto;&quot;&gt;). Which you can download from &lt;/span&gt;&lt;b style=&quot;font-family: Georgia, Utopia, &#39;Palatino Linotype&#39;, Palatino, serif; font-size: 15px; line-height: 21px; text-align: -webkit-auto;&quot;&gt;&lt;a href=&quot;http://commons.apache.org/codec/download_codec.cgi&quot;&gt;here&lt;/a&gt;..&lt;br /&gt;&lt;br /&gt;for client side coding &lt;a href=&quot;http://androracle.blogspot.in/2012/08/image-transfer-to-android-from-java_2.html&quot;&gt;click here&lt;/a&gt;&lt;/b&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://androracle.blogspot.com/feeds/6004014784101432103/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://androracle.blogspot.com/2012/08/image-transfer-to-android-from-java.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/559085935872346632/posts/default/6004014784101432103'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/559085935872346632/posts/default/6004014784101432103'/><link rel='alternate' type='text/html' href='http://androracle.blogspot.com/2012/08/image-transfer-to-android-from-java.html' title='Image Transfer to Android from Java over Sockets'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/10580831359890448769</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total><georss:featurename>Jaipur, Rajasthan, India</georss:featurename><georss:point>26.9124165 75.7872879</georss:point><georss:box>26.685875 75.4714309 27.138958 76.10314489999999</georss:box></entry><entry><id>tag:blogger.com,1999:blog-559085935872346632.post-3327074287578690160</id><published>2012-08-02T13:48:00.001-07:00</published><updated>2012-08-02T13:58:42.978-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="android"/><category scheme="http://www.blogger.com/atom/ns#" term="android image transfer"/><category scheme="http://www.blogger.com/atom/ns#" term="android java communication"/><category scheme="http://www.blogger.com/atom/ns#" term="file transfer"/><category scheme="http://www.blogger.com/atom/ns#" term="image transfer over socket"/><category scheme="http://www.blogger.com/atom/ns#" term="socket. java"/><title type='text'>Image Transfer to Android from Java over Sockets</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
At the client side on android we received the base64String now we decode it into byte array. For this we have include &lt;a href=&quot;https://www.box.com/s/c22c3a1503f56b0f84fd&quot; target=&quot;_blank&quot;&gt;Base64&lt;/a&gt; class in our project. which you can download from &lt;a href=&quot;https://www.box.com/s/c22c3a1503f56b0f84fd&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;. Copy this class file and paste into your src folder. Now import it into your AndroidClient.java class, which is as follows.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;height: 500px; overflow: scroll;&quot;&gt;
&lt;table style=&quot;border: 1px solid;&quot;&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;br /&gt;
package com.example.demoimage;&lt;br /&gt;
&lt;span style=&quot;text-align: left;&quot;&gt;import java.io.DataInputStream;&lt;/span&gt;&lt;br /&gt;
import java.io.DataOutputStream;&lt;br /&gt;
import java.io.IOException;&lt;br /&gt;
import java.net.Socket;&lt;br /&gt;
import java.net.UnknownHostException;&lt;br /&gt;
&lt;br /&gt;
import android.app.Activity;&lt;br /&gt;
import android.graphics.Bitmap;&lt;br /&gt;
import android.graphics.BitmapFactory;&lt;br /&gt;
import android.os.Bundle;&lt;br /&gt;
import android.util.Log;&lt;br /&gt;
import android.view.View;&lt;br /&gt;
import android.widget.Button;&lt;br /&gt;
import android.widget.ImageView;&lt;br /&gt;
&lt;br /&gt;
public class MainActivity extends Activity {&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;ImageView imageView;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;Socket socket = null;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;DataOutputStream dataOutputStream = null;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;DataInputStream dataInputStream = null;&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;/** Called when the activity is first created. */&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;@Override&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;public void onCreate(Bundle savedInstanceState) {&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;super.onCreate(savedInstanceState);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;setContentView(R.layout.activity_main);&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;imageView = (ImageView) findViewById(R.id.imageView1);&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;try {&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;socket = new Socket(&quot;Server&#39;s IP Address, 13267);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;dataOutputStream = new DataOutputStream(socket.getOutputStream());&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;dataInputStream = new DataInputStream(socket.getInputStream());&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;// dataOutputStream.writeUTF(textOut.getText().toString());&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;String base64Code = dataInputStream.readUTF();&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;Log.d(&quot;String&quot;, &quot;:&quot; + base64Code);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;//&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;byte[] decodedString = null;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;try {&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;decodedString = Base64.decode(base64Code);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;} catch (Exception e) {&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;// TODO Auto-generated catch block&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;e.printStackTrace();&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;Log.d(&quot;ErrorHere&quot;, &quot;&quot; + e);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;}&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;Log.d(&quot;St--&quot;, &quot;:&quot; + decodedString.length);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;Bitmap bitmap = BitmapFactory.decodeByteArray(decodedString, 0,&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt;decodedString.length);&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;imageView.setImageBitmap(bitmap);&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;} catch (UnknownHostException e) {&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;// TODO Auto-generated catch block&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;e.printStackTrace();&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;} catch (Exception e) {&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;// TODO Auto-generated catch block&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;e.printStackTrace();&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;Log.d(&quot;Error&quot;, &quot;&quot; + e);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;} finally {&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;if (socket != null) {&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;try {&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt;socket.close();&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;} catch (IOException e) {&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt;// TODO Auto-generated catch block&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt;e.printStackTrace();&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;}&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;}&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;if (dataOutputStream != null) {&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;try {&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt;dataOutputStream.close();&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;} catch (IOException e) {&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt;// TODO Auto-generated catch block&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt;e.printStackTrace();&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;}&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;}&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;if (dataInputStream != null) {&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;try {&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt;dataInputStream.close();&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;} catch (IOException e) {&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt;// TODO Auto-generated catch block&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt;e.printStackTrace();&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;}&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;}&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;}&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;br /&gt;
&lt;br /&gt;
}&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;br /&gt;
when we start this activity the output screen will display the image. Here i includes screenshot of the output.
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh_ezROqmZ-6JzbN-mZ5j1oAB3jtYOBfFdOCYarJiXV3BjoNTLT7ISvL992oO5CfmZ2uqih9r017t2VGyHActWXmpOFNAXejZV57NomRkkH3qkZO8JWT8kJ6iq3J80rof4OV87jrb91BiA/s1600/Untitled.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; height=&quot;223&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh_ezROqmZ-6JzbN-mZ5j1oAB3jtYOBfFdOCYarJiXV3BjoNTLT7ISvL992oO5CfmZ2uqih9r017t2VGyHActWXmpOFNAXejZV57NomRkkH3qkZO8JWT8kJ6iq3J80rof4OV87jrb91BiA/s400/Untitled.png&quot; title=&quot;OutputScreen&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://androracle.blogspot.com/feeds/3327074287578690160/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://androracle.blogspot.com/2012/08/image-transfer-to-android-from-java_2.html#comment-form' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/559085935872346632/posts/default/3327074287578690160'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/559085935872346632/posts/default/3327074287578690160'/><link rel='alternate' type='text/html' href='http://androracle.blogspot.com/2012/08/image-transfer-to-android-from-java_2.html' title='Image Transfer to Android from Java over Sockets'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/10580831359890448769</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh_ezROqmZ-6JzbN-mZ5j1oAB3jtYOBfFdOCYarJiXV3BjoNTLT7ISvL992oO5CfmZ2uqih9r017t2VGyHActWXmpOFNAXejZV57NomRkkH3qkZO8JWT8kJ6iq3J80rof4OV87jrb91BiA/s72-c/Untitled.png" height="72" width="72"/><thr:total>3</thr:total><georss:featurename>Jaipur, Rajasthan, India</georss:featurename><georss:point>26.9124165 75.7872879</georss:point><georss:box>26.685875 75.4714309 27.138958 76.10314489999999</georss:box></entry><entry><id>tag:blogger.com,1999:blog-559085935872346632.post-3552877481445967668</id><published>2012-07-13T03:45:00.000-07:00</published><updated>2012-08-07T04:25:17.579-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="connection between java classes"/><category scheme="http://www.blogger.com/atom/ns#" term="java"/><category scheme="http://www.blogger.com/atom/ns#" term="java server"/><category scheme="http://www.blogger.com/atom/ns#" term="oracle connectivity to java"/><category scheme="http://www.blogger.com/atom/ns#" term="oracle-java"/><category scheme="http://www.blogger.com/atom/ns#" term="socket programming"/><title type='text'>Java Class as Server for client with oracle database connectivity</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot;&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;


&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;background-color: white; font-size: small; &quot;&gt;Hello friends..&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;div style=&quot;font-weight: normal;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;I have gone through many websites for connectivity between android and oracle. But i didn&#39;t find any solution. If you are searching for the same than this blog will help you. I have use&amp;nbsp;&lt;b&gt;&lt;u&gt;JAVA Socket&amp;nbsp;Programming&amp;nbsp;&lt;/u&gt;&lt;/b&gt;to connect oracle to your android Emulator. For this we have to use java.net.* package.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-weight: normal;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;Java.net.Socket provides client side TCP socket. In this&amp;nbsp;communication&amp;nbsp;we are going to use android as client and java program as server. This program can be run on both(wi-fi or LAN). you just have to enter the server&#39;s IP adress.&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;In this post i describe about java server class.&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small; font-weight: normal;&quot;&gt;Now in eclipse create new java project and simple copy and paste the following code.&lt;/span&gt;&lt;/div&gt;
&lt;/h2&gt;
&lt;/div&gt;
&lt;div style=&quot;height: 500px; overflow: scroll; width: 100%;&quot;&gt;
&lt;table style=&quot;border: 1px solid;&quot;&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;br /&gt;
&lt;br /&gt;
import java.io.DataInputStream;&lt;br /&gt;
import java.io.DataOutputStream;&lt;br /&gt;
import java.io.IOException;&lt;br /&gt;
import java.net.ServerSocket;&lt;br /&gt;
import java.net.Socket;&lt;br /&gt;
import java.sql.*;&lt;br /&gt;
&lt;br /&gt;
public class ConnectOracle {&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;public static void main(String[] args) {&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;String driver = &quot;oracle.jdbc.driver.OracleDriver&quot;; //&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;String serverName = &quot;localhost&quot;;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;String portNumber = &quot;1521&quot;;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;String db = &quot;XE&quot;;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;String url = &quot;jdbc:oracle:thin:@&quot; + serverName + &quot;:&quot; + portNumber + &quot;:&quot;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;+ db; // connectOracle is the data&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;// source name&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;String user = &quot;system&quot;; // username of oracle database&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;String pwd = &quot;root&quot;; // password of oracle database&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;Connection con = null;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;ServerSocket serverSocket = null;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;Socket socket = null;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;DataInputStream dataInputStream = null;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;DataOutputStream dataOutputStream = null;&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;try {&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;Class.forName(driver);// for loading the jdbc driver&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;System.out.println(&quot;JDBC Driver loaded&quot;);&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;con = DriverManager.getConnection(url, user, pwd);// for&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;                &lt;/span&gt;// establishing&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;// connection&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;// with database&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;Statement stmt = con.createStatement();&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;serverSocket = new ServerSocket(8888);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;System.out.println(&quot;Listening :8888&quot;);&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;while (true) {&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;try {&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt;socket = serverSocket.accept();&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt;System.out.println(&quot;Connection Created&quot;);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt;dataInputStream = new DataInputStream(&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;       &lt;/span&gt;socket.getInputStream());&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt;dataOutputStream = new DataOutputStream(&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;       &lt;/span&gt;socket.getOutputStream());&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt;System.out.println(&quot;ip: &quot; + socket.getInetAddress());&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt;// System.out.println(&quot;message: &quot; +&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt;// dataInputStream.readUTF());&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt;ResultSet res=stmt.executeQuery(&quot;select * from food_category&quot;);&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt;while(res.next()){&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;      &lt;/span&gt;System.out.println(res.getString(1));&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt;}&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;} catch (IOException e) {&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt;// TODO Auto-generated catch block&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt;e.printStackTrace();&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;}&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;if (dataInputStream != null) {&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt;try {&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;      &lt;/span&gt;dataInputStream.close();&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt;} catch (IOException e) {&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;      &lt;/span&gt;// TODO Auto-generated catch block&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;      &lt;/span&gt;e.printStackTrace();&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt;}&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;}&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;if (dataOutputStream != null) {&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt;try {&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;      &lt;/span&gt;dataOutputStream.close();&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt;} catch (IOException e) {&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;      &lt;/span&gt;// TODO Auto-generated catch block&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;      &lt;/span&gt;e.printStackTrace();&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt;}&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;}&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;}&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;} catch (Exception e) {&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;// TODO Auto-generated catch block&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;e.printStackTrace();&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;}&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;br /&gt;
}&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;div style=&quot;font-size: 24px; font-weight: bold;&quot;&gt;
&lt;span style=&quot;background-color: white; font-size: small; font-weight: normal;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-size: 24px; font-weight: bold;&quot;&gt;
&lt;span style=&quot;background-color: white; font-size: small; font-weight: normal;&quot;&gt;For oracle connectivity you have to add jar file which you can download from&amp;nbsp;&lt;/span&gt;&lt;b style=&quot;background-color: white; font-size: medium;&quot;&gt;&lt;a href=&quot;http://www.oracle.com/technetwork/database/enterprise-edition/jdbc-10201-088211.html&quot;&gt;here&lt;/a&gt;.&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;In eclipse you can use this jar file by configure build path(&lt;/span&gt;&lt;b style=&quot;background-color: white;&quot;&gt;right click&amp;nbsp;&lt;/b&gt;&lt;span style=&quot;background-color: white;&quot;&gt;on your project in&lt;/span&gt;&lt;b style=&quot;background-color: white;&quot;&gt;&amp;nbsp;project explorer&lt;/b&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: white;&quot;&gt;and then click on build&lt;/span&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;b style=&quot;background-color: white;&quot;&gt;path-&amp;gt;configure build path&amp;nbsp;&lt;/b&gt;&lt;span style=&quot;background-color: white;&quot;&gt;and then&lt;/span&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;b style=&quot;background-color: white;&quot;&gt;add external jar file&lt;/b&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: white;&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-size: 24px; font-weight: bold;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;span style=&quot;text-align: -webkit-auto;&quot;&gt;serverSocket = new ServerSocket(8888);&lt;br /&gt;Here we can change port number. But this port number must be same for the&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: white; text-align: -webkit-auto;&quot;&gt;both&lt;/span&gt;&lt;span style=&quot;background-color: white; text-align: -webkit-auto;&quot;&gt;&amp;nbsp;client and server to communicate.&lt;/span&gt;&lt;br /&gt;
We assumes that there is a table food_category in the user &#39;system&#39; with the password &#39;root&#39;. Here i used oracle 10g XE.&lt;/div&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://androracle.blogspot.com/feeds/3552877481445967668/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://androracle.blogspot.com/2012/07/java-class-as-server-for-client-with.html#comment-form' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/559085935872346632/posts/default/3552877481445967668'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/559085935872346632/posts/default/3552877481445967668'/><link rel='alternate' type='text/html' href='http://androracle.blogspot.com/2012/07/java-class-as-server-for-client-with.html' title='Java Class as Server for client with oracle database connectivity'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/10580831359890448769</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-559085935872346632.post-1931165463537570558</id><published>2012-07-12T22:59:00.000-07:00</published><updated>2012-07-13T04:20:38.442-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="android"/><category scheme="http://www.blogger.com/atom/ns#" term="android oracle connectivity"/><category scheme="http://www.blogger.com/atom/ns#" term="android oracle connectivity thorugh java socket programming"/><category scheme="http://www.blogger.com/atom/ns#" term="java"/><category scheme="http://www.blogger.com/atom/ns#" term="oracle"/><category scheme="http://www.blogger.com/atom/ns#" term="socket programming"/><title type='text'>Client side programming on android</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Hello friends..&lt;br /&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;Here for android client you just have to enter the server&#39;s IP adress.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;border: 1px solid black; font-size: 13px; line-height: 18px; text-align: -webkit-auto;&quot;&gt;&lt;code&gt;socket = new Socket(&quot;Server&#39;s IP Here&quot;, 8888);&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
For android client follow these steps.
&lt;br /&gt;
&lt;ol style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;&lt;span style=&quot;background-color: white;&quot;&gt;Create a new Android project from eclipse. paste the following code in the java class.&lt;/span&gt;
&lt;div style=&quot;height: 400px; overflow: scroll; width: 100%;&quot;&gt;
&lt;table &quot;=&quot;&quot;&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;br /&gt;
&lt;pre style=&quot;border: 1px solid black; font-size: 13px; line-height: 18px;&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: black;&quot;&gt;package com.rahul.android;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Socket;
import java.net.UnknownHostException;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public&lt;/span&gt; class AndroidClient extends Activity {

EditText textOut;
TextView textIn;

 /** Called when the activity is first created. */
 @Override
 public void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     setContentView(R.layout.main);
  
     textOut = (EditText)findViewById(R.id.textout);
     Button buttonSend = (Button)findViewById(R.id.send);
     textIn = (TextView)findViewById(R.id.textin);
     buttonSend.setOnClickListener(buttonSendOnClickListener);
 }

 Button.OnClickListener buttonSendOnClickListener
 = new Button.OnClickListener(){

@Override
public void onClick(View arg0) {
 // TODO Auto-generated method stub
 Socket socket = null;
 DataOutputStream dataOutputStream = null;
 DataInputStream dataInputStream = null;

 try {
  socket = new Socket(&quot;S&lt;span style=&quot;background-color: white; text-align: left;&quot;&gt;erver&#39;s IP Here&lt;/span&gt;&quot;, 8888);
  dataOutputStream = new DataOutputStream(socket.getOutputStream());
  dataInputStream = new DataInputStream(socket.getInputStream());
  dataOutputStream.writeUTF(textOut.getText().toString());
  textIn.setText(dataInputStream.readUTF());
 } catch (UnknownHostException e) {
  // TODO Auto-generated catch block
  e.printStackTrace();
 } catch (IOException e) {
  // TODO Auto-generated catch block
  e.printStackTrace();
 }
 finally{
  if (socket != null){
   try {
    socket.close();
   } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
   }
  }

  if (dataOutputStream != null){
   try {
    dataOutputStream.close();
   } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
   }
  }

  if (dataInputStream != null){
   try {
    dataInputStream.close();
   } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
   }
  }
 }
}};
}&lt;/code&gt;&lt;/pre&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;br /&gt;
now copy the following code into main.xml file&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;height: 400px; overflow: scroll;&quot;&gt;
&lt;pre style=&quot;border: 1px solid black; color: #666666; font-size: 13px; line-height: 18px; text-align: -webkit-auto;&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&amp;gt;
&amp;lt;LinearLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
 android:orientation=&quot;vertical&quot;
 android:layout_width=&quot;fill_parent&quot;
 android:layout_height=&quot;fill_parent&quot;
 &amp;gt;
&amp;lt;TextView
 android:layout_width=&quot;fill_parent&quot;
 android:layout_height=&quot;wrap_content&quot;
 android:text=&quot;@string/hello&quot;
 /&amp;gt;
&amp;lt;EditText
 android:id=&quot;@+id/textout&quot;
 android:layout_width=&quot;fill_parent&quot;
 android:layout_height=&quot;wrap_content&quot;
 /&amp;gt;
&amp;lt;Button
 android:id=&quot;@+id/send&quot;
 android:layout_width=&quot;fill_parent&quot;
 android:layout_height=&quot;wrap_content&quot;
 android:text=&quot;Send&quot;
 /&amp;gt;
&amp;lt;TextView
 android:id=&quot;@+id/textin&quot;
 android:layout_width=&quot;fill_parent&quot;
 android:layout_height=&quot;wrap_content&quot;
 /&amp;gt;
&amp;lt;/LinearLayout&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
after this you have to modify&amp;nbsp;
&lt;span style=&quot;font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18px; text-align: -webkit-auto;&quot;&gt;AndroidManifest&lt;/span&gt;&amp;nbsp;.xml file for permission to access internet&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18px; text-align: -webkit-auto;&quot;&gt;&amp;lt;uses-permission android:name=&quot;android.permission.INTERNET&quot;/&amp;gt;&lt;/span&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18px; text-align: -webkit-auto;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18px; text-align: -webkit-auto;&quot;&gt;put the follwing code after the application tag in&amp;nbsp;&lt;/span&gt;
&lt;span style=&quot;font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18px; text-align: -webkit-auto;&quot;&gt;AndroidManifest&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18px; text-align: -webkit-auto;&quot;&gt;.mxl file.&lt;/span&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://androracle.blogspot.com/feeds/1931165463537570558/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://androracle.blogspot.com/2012/07/client-side-programming-on-android.html#comment-form' title='5 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/559085935872346632/posts/default/1931165463537570558'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/559085935872346632/posts/default/1931165463537570558'/><link rel='alternate' type='text/html' href='http://androracle.blogspot.com/2012/07/client-side-programming-on-android.html' title='Client side programming on android'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/10580831359890448769</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>5</thr:total></entry></feed>