Android Question insert image into sql server from android phone

Status
Not open for further replies.

Stephenz43

Member
Licensed User
Longtime User
Greetings

I use the following syntax to insert a image on my desktop PC. I would like to now use it in B4A but I cant get the syntax right.

iNSERT INTO TableA (Id,Images)
SELECT 1, BulkColumn
FROM Openrowset( Bulk 'C:\th.jpg', Single_Blob) as image

What would the syntax be in B4A including the correct file location reference.

Thank you
Steve
 

Stephenz43

Member
Licensed User
Longtime User
The PHP script doesn't support blobs. You will need to modify it. You can send the image encoded as base64 string and decode it in the php script.

Another option is to use RDC which does support blobs (and is more efficient).

I want to make sure I gave you all the right info. I'm using MS sqlServer with the script I found here
 
Upvote 0

Stephenz43

Member
Licensed User
Longtime User
I am taking your advice and trying to use RDC... I'm getting the following error


C:\WINDOWS\system32>"C:\Program Files (x86)\Java\jdk1.7.0_13\bin\java" -Xmx256m
-cp .;libs\*;jdbc_driver\* anywheresoftware.b4a.remotedatabase.RemoteServer
Error: Could not find or load main class anywheresoftware.b4a.remotedatabase.Rem
oteServer

C:\WINDOWS\system32>pause
Press any key to continue . . .
 
Upvote 0

Stephenz43

Member
Licensed User
Longtime User
Greetings again

I'm paste the server starting but now dealing with the following java eof exception

any guidence would be appreciated.

thank you



C:\RDC\RDC-Server\RemoteDatabaseConnector>"C:\Program Files (x86)\Java\jdk1.7.0_
13\bin\java" -Xmx256m -cp .;libs\*;jdbc_driver\* anywheresoftware.b4a.remotedata
base.RemoteServer
B4A Remote Database Connecter (version 0.9)
loading: C:\RDC\RDC-Server\RemoteDatabaseConnector\config.properties
2014-09-10 21:35:18.588:INFO::jetty-7.4.2.v20110526
2014-09-10 21:35:18.621:INFO::started o.e.j.s.ServletContextHandler{/,null}
Sep 10, 2014 9:35:18 PM com.mchange.v2.log.MLog <clinit>
INFO: MLog clients using java 1.4+ standard logging.
Sep 10, 2014 9:35:18 PM com.mchange.v2.c3p0.C3P0Registry banner
INFO: Initializing c3p0-0.9.2.1 [built 20-March-2013 11:16:28 +0000; debug? true
; trace: 10]
2014-09-10 21:35:18.820:INFO::Started SelectChannelConnector@0.0.0.0:17178 START
ING
java.io.EOFException
at java.util.zip.GZIPInputStream.readUByte(GZIPInputStream.java:264)
at java.util.zip.GZIPInputStream.readUShort(GZIPInputStream.java:254)
at java.util.zip.GZIPInputStream.readHeader(GZIPInputStream.java:163)
at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:78)
at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:90)
at anywheresoftware.b4a.remotedatabase.Servlet.doGet(Servlet.java:75)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:538
)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java
:478)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandl
er.java:937)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:
406)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandle
r.java:871)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.j
ava:117)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper
.java:110)
at org.eclipse.jetty.server.Server.handle(Server.java:346)
at org.eclipse.jetty.server.HttpConnection.handleRequest(HttpConnection.
java:589)
at org.eclipse.jetty.server.HttpConnection$RequestHandler.headerComplete
(HttpConnection.java:1048)
at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:601)
at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:214)

at org.eclipse.jetty.server.HttpConnection.handle(HttpConnection.java:41
1)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEn
dPoint.java:535)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEnd
Point.java:40)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool
.java:529)
at java.lang.Thread.run(Thread.java:722)
 
Upvote 0

Stephenz43

Member
Licensed User
Longtime User
Hi again

Here's where I am currently

From the server after "http://127.0.0.1:17178/?method=test"



RemoteServer is running (Thu Sep 11 15:25:43 PDT 2014)
java.sql.SQLException: An attempt by a client to checkout a Connection has timed out.


Config.properties

#SQL Server
DriverClass=net.sourceforge.jtds.jdbc.Driver
JdbcUrl=jdbc:sqlserver://127.0.0.1/test
User=sa
Password=ranger
ServerPort=17178
#If Debug is true then this file will be reloaded on every query.
#This is useful if you need to modify the queries.
Debug=true


#commands
sql.create_table=CREATE TABLE animals (\
id INT NOT NULL AUTO_INCREMENT,\
name CHAR(30) NOT NULL,\
image BLOB,\
PRIMARY KEY (id))

Again any help would be appreciated
thanks
steve
 
Upvote 0

Stephenz43

Member
Licensed User
Longtime User
more info for the above

internal ip = 192.168.1.100
servername = STEVE\SQLEXPRESS
database = test
listening to port 1433
 
Upvote 0

Stephenz43

Member
Licensed User
Longtime User
Greetings on again

I have had success in connecting to the server and inserting data through the internal and expernal ip address.
The only remaining issue is to figure out how to insert a image file from the smartphone. I see a few comments refering to the methods filetobytes,imagestobytes,bytestoimages but cannot find a sample to study. I am new to transmitting imagefiles and could use some help.

Thank you
Steve
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
This code will send a file:
B4X:
Dim cmd As DBCommand
cmd.Initialize
cmd.Name = "insert_animal"
cmd.Parameters = Array As Object("a1", reqManager.FileToBytes(File.DirAssets, "image.png"))
reqManager.ExecuteCommand(cmd, "cmd")

insert_animal statement is the one from this example: http://www.b4x.com/android/forum/threads/31540
 
Upvote 0
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…