B4J Tutorial SQL Tutorial

Discussion in 'B4J Tutorials' started by Erel, Dec 1, 2013.

  1. Erel

    Erel Administrator Staff Member Licensed User

    You should start a new thread for this (a bit too broad) question. You can use any MySQL server you like. xampp is a good option.
     
  2. sorex

    sorex Expert Licensed User

    Does anyone know what the driver name is for MS's original MSSQL JDB driver?
     
  3. sorex

    sorex Expert Licensed User

    this is working

    Code:
    #AdditionalJar: sqljdbc4.jar
    Code:
    sql1.Initialize("com.microsoft.sqlserver.jdbc.SQLServerDriver","jdbc:sqlserver://sqlserver:1433;databaseName=intranet;user=xxx;password=xxx;")
    sqljdbc.jar doesn't work on java 1.8

    you can download sqljdbc_4.0.2206.100_enu.tar.gz which doesn't require an install from http://www.microsoft.com/en-us/download/details.aspx?displaylang=en&id=11774

    extract it or browse with Total Commander and copy the file sqljdbc_4.0\enu\sqljdbc4.jar to you additional libraries folder.
     
  4. Erel

    Erel Administrator Staff Member Licensed User

  5. sorex

    sorex Expert Licensed User

    thanks for the hint, @Erel.

    that one seems to be up to 4 times faster than the one from Microsoft in some cases.
     
    Erel likes this.
  6. sorex

    sorex Expert Licensed User

    it seems that I was too quick with my results.

    when I ran it in release mode I got errors that the resultset was not initialized.

    I had both MSSQL & JTDS as additional JAR in my project.

    When I remove the MSSQL one it doesn't work in debug mode either.

    Funny thing is that when I make a typo in the driver class name (net.sourceforge.jtds.jdbc.Driver) its not working either so my guess is it tried to use the right one anyway.

    Is there an error that I can display that might show more info about the connect failure?
     
  7. sorex

    sorex Expert Licensed User

    ok, I missed the JTDS part in the connection string which is apparently needed. Strange that it worked without when the MSSQL lib was added.

    Code:
    sql1.Initialize("net.sourceforge.jtds.jdbc.Driver","jdbc:jtds:sqlserver://servername:1433/databasename;user=xxx;password=xxx")
     
    Ejbh likes this.
  8. vfafou

    vfafou Active Member Licensed User

    Hello!
    Is it a good practice, when we have a thread pool of connections, to do the following(?):
    Code:
    If Not(SQL.IsInitialized) Then SQL = Pool.GetConnection
    Thank you in advance!
     
  9. Erel

    Erel Administrator Staff Member Licensed User

    Please start a new thread for this question.
     
  10. Croïd

    Croïd Active Member Licensed User

    you can tell me what's wrong in my file ?

    Error: (ConnectException) java.net.ConnectException: Connection timed out: connect
     

    Attached Files:

    Last edited: Sep 17, 2016
  11. Erel

    Erel Administrator Staff Member Licensed User

    The remote database is probably not configured to allow remote connections.
     
  12. Croïd

    Croïd Active Member Licensed User

    Thanks Erel

    It is a base of a service provider. With B4A application you can connect

    Is it different between B4A and b4j ?
     
  13. Erel

    Erel Administrator Staff Member Licensed User

    How are you connecting with B4A?
     
  14. Croïd

    Croïd Active Member Licensed User

    Yes with " lib: MSMySql no SQL

    Code:
    Dim db As MySQL
    ------
    db.Initialize(
    "MySQL","sqlx.freemysql.net","sqluser","sqlpassw","sqluser")
    db.QueryASync(
    "SELECT * FROM Table;","")
    db.CloseDatabase
    sample express write db
     
    Last edited: Sep 18, 2016
  15. Erel

    Erel Administrator Staff Member Licensed User

    Why are you using jtds if it is a MySQL database?

    See the code from the first post.
     
  16. Croïd

    Croïd Active Member Licensed User

    Because if I take the first post : Error: (UnknownHostException) java.net.UnknownHostException: sql7.freemysqlhosting.net;user=sqluser;password=passw

    Code:
    #AdditionalJar: mysql-connector-java-5.1.39-bin.jar
     
  17. Erel

    Erel Administrator Staff Member Licensed User

    Please start a new thread in the questions forum and provide more information about the database that you are connecting to.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice