B4J Question Is it possible to create mysql database with b4j?

DonManfred

Expert
Licensed User
Longtime User
I guess it depends on the Rights you gave to the Database for the User you are using.
If the user has the right it should work.
 
Upvote 0

Addo

Well-Known Member
Licensed User
Longtime User
@DonManfred i am talking about creating database, not connecting to an existing database and doing queries . As example execution of this query
SQL:
CREATE DATABASE db_name;

Is it possible to connect to mysql server using Jsql and create a database with it?
 
Upvote 0

Addo

Well-Known Member
Licensed User
Longtime User
what i am confusing in is the right parameter that i should use in Sql Initialize. in order to create a database

B4X:
'is this a correct Parameter ?
sql.Initialize("com.mysql.jdbc.Driver", "jdbc:mysql://localhost:"&dpPort&"/?characterEncoding=utf8")

i am not adding database in the parameter since i am not trying to connect to a Database instead iam trying to create one
 
Upvote 0

Addo

Well-Known Member
Licensed User
Longtime User
i confirm it is working as expected

i was confused here is the working example

B4X:
Sub createdatabase
    
Dim sql As SQL


Try
    
sql.Initialize2("com.mysql.jdbc.Driver","jdbc:mysql://localhost:"&dpPort&"/?characterEncoding=utf8","root", "123")

Dim SQLQuery As String = "CREATE DATABASE anyname;"

sql.ExecNonQuery(SQLQuery)

sql.Close


Catch
Log(LastException)
End Try
    
    
End Sub

Thank you Guys .
 
Upvote 0
Top