Android Question SQL SERVER EXPRESS EDITION AND B4ANDROID CRUD'S

DonManfred

Expert
Licensed User
Longtime User
- NO need to write anything UPPERCASE (Title).
- You should use jRDC2 for the Databaseconnection and connect your B4A App to you JRDC2 Server.
 
Upvote 0

FabianJi

Member
Licensed User
Longtime User
Hi DonManfred, Thankyou so much, but i would like to have a sample with SQL SERVER not, mysql, if you have it, can to share it with me???, thank you again
 
Upvote 0

josejad

Expert
Licensed User
Longtime User
Read about jRDC2. The sample is for Mysql, but you just need to change the config properties to connect with any other database.
jRDC2 can work with any database that provides a JDBC driver. All popular databases are supported.
 
Upvote 0

FabianJi

Member
Licensed User
Longtime User
This si my config

#MS SQL Server configuration:
DriverClass=net.sourceforge.jtds.jdbc.Driver
JdbcUrl=jdbc:jtds:sqlserver://192.168.2.102/clinica

**My Instance have pasword, how add it?

this is my issue.

Waiting for debugger to connect...
Program started.
2019-01-13 10:05:39.014:INFO::main: Logging initialized @617ms to org.eclipse.jetty.util.log.StdErrLog
ene 13, 2019 10:05:39 AM com.mchange.v2.log.MLog
INFORMACIÓN: MLog clients using java 1.4+ standard logging.
ene 13, 2019 10:05:39 AM com.mchange.v2.c3p0.C3P0Registry
INFORMACIÓN: Initializing c3p0-0.9.5.2 [built 08-December-2015 22:06:04 -0800; debug? true; trace: 10]
Ha ocurrido un error en la línea: 19 (RDCConnector)
java.lang.NumberFormatException: For input string: "null"
at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:2043)
at sun.misc.FloatingDecimal.parseDouble(FloatingDecimal.java:110)
at java.lang.Double.parseDouble(Double.java:538)
at anywheresoftware.b4a.BA.ObjectToNumber(BA.java:395)
at b4j.example.rdcconnector._initialize(rdcconnector.java:60)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:632)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:234)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:91)
at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:98)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:78)
at b4j.example.main.main(main.java:29)

I dont know how follow
 
Upvote 0

josejad

Expert
Licensed User
Longtime User
Please, use code tags to show your code.
You can set your user, password and port with last three lines:
B4X:
#MS SQL Server configuration:
#DATABASE CONFIGURATION
DriverClass=net.sourceforge.jtds.jdbc.Driver
JdbcUrl=jdbc:jtds:sqlserver://192.168.2.102/clinica
User=<here your user>
Password=<here your password>
#Java server port
ServerPort=<here you jRDC2 port>

You should start with this thread if you are not familiar with jRDC: Remote Database Connector (RDC) - Connect to any remote DB
This is the first version and explain some things you should know before using jRDC2

Once your B4J server is running, you should test in your browser:
B4X:
http://<your B4J server ip>:<port>/test

and you should get something like:
B4X:
RemoteServer is running (01/13/2019 18:49:43)
Connection successful.

Watching your log, the line:
B4X:
Ha ocurrido un error en la línea: 19 (RDCConnector)
java.lang.NumberFormatException: For input string: "null"
says you have a problem in line 19 of RDCConnector, which is:
B4X:
serverPort = config.Get("ServerPort")
So based in the config.properties you've published, seems you have to add the:
B4X:
User=<here your user>
Password=<here your password>
#Java server port
ServerPort=<here you jRDC2 port>
lines
 
Upvote 0

FabianJi

Member
Licensed User
Longtime User
He generado varias pruebas sin exito:

Script config.properties

#example of MS SQL Server configuration:
DriverClass=net.sourceforge.jtds.jdbc.Driver
JdbcUrl=jdbc:jtds:sqlserver://192.168.2.101:1433/baseprueba;instance=SQLEXPRESS
User=sa
Password=1234
ServerPort=17100

El driver jar que uso es :#AdditionalJar: jtds-1.3.1

pero aun no logro conectarme con exito

El output del log es:...........................

jRDC is running (version = 2.21)
feb 10, 2019 12:21:50 PM com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource
INFORMACIÓN: Initializing c3p0 pool... com.mchange.v2.c3p0.ComboPooledDataSource [ acquireIncrement -> 3, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 20000, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, contextClassLoaderSource -> caller, dataSourceName -> 1hge1d1a01o1ul331jjxtn6|1d4e2ba, debugUnreturnedConnectionStackTraces -> false, description -> null, driverClass -> net.sourceforge.jtds.jdbc.Driver, extensions -> {}, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, forceSynchronousCheckins -> false, forceUseNamedDriverClass -> false, identityToken -> 1hge1d1a01o1ul331jjxtn6|1d4e2ba, idleConnectionTestPeriod -> 600, initialPoolSize -> 3, jdbcUrl -> jdbc:jtds:sqlserver://JOB-PC:1433/clinica;instance=SQLEXPRESS;user=sa;password=1234, maxAdministrativeTaskTime -> 0, maxC...
feb 10, 2019 12:25:59 PM com.mchange.v2.resourcepool.BasicResourcePool
ADVERTENCIA: com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask@137ae82 -- Acquisition Attempt Failed!!! Clearing pending acquires. While trying to acquire a needed new resource, we failed to succeed more than the maximum number of allowed acquisition attempts (30). Last acquisition attempt exception:
java.sql.SQLException: Network error IOException: Connection refused: connect
at net.sourceforge.jtds.jdbc.JtdsConnection.<init>(JtdsConnection.java:436)
at net.sourceforge.jtds.jdbc.Driver.connect(Driver.java:184)
at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:175)
at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:220)
at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:206)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:203)
at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1138)
at com.mchange.v2.resourcepool.BasicResourcePool.doAcquireAndDecrementPendingAcquiresWithinLockOnSuccess(BasicResourcePool.java:1125)
at com.mchange.v2.resourcepool.BasicResourcePool.access$700(BasicResourcePool.java:44)
at com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask.run(BasicResourcePool.java:1870)
at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:696)
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at net.sourceforge.jtds.jdbc.SharedSocket.createSocketForJDBC3(SharedSocket.java:288)
at net.sourceforge.jtds.jdbc.SharedSocket.<init>(SharedSocket.java:251)
at net.sourceforge.jtds.jdbc.JtdsConnection.<init>(JtdsConnection.java:331)
... 10 more
feb 10, 2019 12:25:59 PM com.mchange.v2.resourcepool.BasicResourcePool
ADVERTENCIA: Having failed to acquire a resource, com.mchange.v2.resourcepool.BasicResourcePool@154b04f is interrupting all Threads waiting on a resource to check out. Will try again in response to new client requests.
feb 10, 2019 12:25:59 PM com.mchange.v2.resourcepool.BasicResourcePool
ADVERTENCIA: com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask@9d890f -- Acquisition Attempt Failed!!! Clearing pending acquires. While trying to acquire a needed new resource, we failed to succeed more than the maximum number of allowed acquisition attempts (30). Last acquisition attempt exception:
java.sql.SQLException: Network error IOException: Connection refused: connect
at net.sourceforge.jtds.jdbc.JtdsConnection.<init>(JtdsConnection.java:436)
at net.sourceforge.jtds.jdbc.Driver.connect(Driver.java:184)
at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:175)
at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:220)
at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:206)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:203)
at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1138)
at com.mchange.v2.resourcepool.BasicResourcePool.doAcquireAndDecrementPendingAcquiresWithinLockOnSuccess(BasicResourcePool.java:1125)
at com.mchange.v2.resourcepool.BasicResourcePool.access$700(BasicResourcePool.java:44)
at com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask.run(BasicResourcePool.java:1870)
at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:696)
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at net.sourceforge.jtds.jdbc.SharedSocket.createSocketForJDBC3(SharedSocket.java:288)
at net.sourceforge.jtds.jdbc.SharedSocket.<init>(SharedSocket.java:251)
at net.sourceforge.jtds.jdbc.JtdsConnection.<init>(JtdsConnection.java:331)
... 10 more
feb 10, 2019 12:25:59 PM com.mchange.v2.resourcepool.BasicResourcePool
ADVERTENCIA: Having failed to acquire a resource, com.mchange.v2.resourcepool.BasicResourcePool@154b04f is interrupting all Threads waiting on a resource to check out. Will try again in response to new client requests.
feb 10, 2019 12:25:59 PM com.mchange.v2.resourcepool.BasicResourcePool
ADVERTENCIA: com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask@1efef6e -- Acquisition Attempt Failed!!! Clearing pending acquires. While trying to acquire a needed new resource, we failed to succeed more than the maximum number of allowed acquisition attempts (30). Last acquisition attempt exception:
java.sql.SQLException: Network error IOException: Connection refused: connect
at net.sourceforge.jtds.jdbc.JtdsConnection.<init>(JtdsConnection.java:436)
at net.sourceforge.jtds.jdbc.Driver.connect(Driver.java:184)
at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:175)
at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:220)
at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:206)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:203)
at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1138)
at com.mchange.v2.resourcepool.BasicResourcePool.doAcquireAndDecrementPendingAcquiresWithinLockOnSuccess(BasicResourcePool.java:1125)
at com.mchange.v2.resourcepool.BasicResourcePool.access$700(BasicResourcePool.java:44)
at com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask.run(BasicResourcePool.java:1870)
at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:696)
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at net.sourceforge.jtds.jdbc.SharedSocket.createSocketForJDBC3(SharedSocket.java:288)
at net.sourceforge.jtds.jdbc.SharedSocket.<init>(SharedSocket.java:251)
at net.sourceforge.jtds.jdbc.JtdsConnection.<init>(JtdsConnection.java:331)
... 10 more
feb 10, 2019 12:25:59 PM com.mchange.v2.resourcepool.BasicResourcePool
ADVERTENCIA: Having failed to acquire a resource, com.mchange.v2.resourcepool.BasicResourcePool@154b04f is interrupting all Threads waiting on a resource to check out. Will try again in response to new client requests.

NOTA: El firewall esta abajo.

Espero me puedan ayudar, saludos
 
Upvote 0
Top