My Grails app uses a h2 database in dev mode (the default behaviour for Grails apps). The DB connection settings in DataSource.groovy are
dataSource {
pooled = true
jmxExport = true
driverClassName = "org.h2.Driver"
username = "sa"
password = ""
dbCreate = "create-drop" // one of 'create', 'create-drop', 'update', 'validate', ''
url = "jdbc:h2:mem:devDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE"
}
I'm trying to setup a connection for this database using IntelliJ IDEA's database client tools. I start off creating the connection like so
Then in the following dialog, I enter the JDBC URL
And choose all available databases on the "Schemas & Tables" tab.
The "Test Connection" button indicates success, but as you can see from the red circle, no tables are found. It seems like I've correctly setup a connection to the h2 server, but not the schema itself.
BTW, I try to setup this connection once the app is running, so I'm sure that the schema/tables do actually exist.
Your configuration is for an h2:mem database. Memory Databases have no tables upon connecting to them, and any & all tables are lost when all the connections are closed. Furthermore, a (named) in memory database is unique to the JVM process that opens it. From the H2 documentation:
Sometimes multiple connections to the same in-memory database are required. In this case, the database URL must include a name. Example: jdbc:h2:mem:db1. Accessing the same database using this URL only works within the same virtual machine and class loader environment. (Emphasis added)
This means IDEA will create a unique devDb in its JVM (and classloader) space and your application will create a unique devDb in its JVM (and classloader) space. You can not connect to an in memory database from an external JVM process.
If you want to connect both your application and IntelliJ IDEA (or any other DB tool) to an H2 database at the same time, you will need to either
use an embedded database (that writes to a file) in your application and use Mixed Mode to allow IntelliJ IDEA (and/or other database tools) to connect to it
use a server mode database
See http://www.h2database.com/html/features.html#connection_modes for more information.
This article has a great write up on how to set up the IntelliJ database client to connect to an H2 in-memory database if you happen to be using Spring Boot: http://web.archive.org/web/20160513065923/http://blog.techdev.de/querying-the-embedded-h2-database-of-a-spring-boot-application/
Basically, you wrap the in-memory database with a tcp server, then you have an access point to connect with a sql client via remote access.
Try to open http://localhost:8080/dbconsole and fill your jdbc url
During development you can use grails h2 dbconsole
Let's imagine you've already created entities (Users, Addresses)
Step 1. In application.yml file add H2 properties.
server:
port: 8080
spring:
datasource:
url: jdbc:h2:~/data/parserpalce (for Mac OS)
username: sa
password: password
driver-class-name: org.h2.Driver
jpa:
database-platform: org.hibernate.dialect.H2Dialect
hibernate:
ddl-auto: update
h2:
console:
enabled: true
Step 2. Add H2 Database client
Step 3. Configure H2 database client properties based on your application.yml properties.
Step 4. Run the application.
Step 5. Check if tables(Users, Addresses) are created.
Or you can use H2 console for it in browser:
http://localhost:8080/h2-console
P.S. Do not forget to paste appropriate values in fields!
Related
I use ADO connectionstring to MariaDB in dBase and when the connection is unsuccessful (invalid userid, pwd, port number, IP address, databasename or if the server is not running), I get the MariaDB datasource connector wizard. Once I cancel or complete the wizard (both successfully or unsuccessfully), I get the ADO error into dBase.
Is there a way to disable this wizard and just return the error?
For anyone interested, adding 16 (for NO_PROMPT) to the "option" part of the connectionstring disables the popup.
Just in case anyone is looking for the same option for SQLserver, look here: https://learn.microsoft.com/en-us/sql/ado/reference/ado-api/connectpromptenum?view=sql-server-ver15
oConn.Properties("Prompt") = adPromptNever or any other desired option from the above link
oConn.Open "Driver={SQL Server Native Client 10.0};Server=myServerAddress;Database=myDataBase;"
I'm trying to get data from PostgreSQL from another computer and move to MySQL on my local computer.
I got libmysql55.dll from Zeos repository.
I had to create a program to fix a lot of mistakes over database.
One error is happening:
SQL Error: Access denied for user 'xxxx'#'localhost' (using password: YES)
I have information about: database, hostname, user and password.
ZConPropro.HostName := edtProproIP.Text;
ZConPropro.User := edtUser.Text;
ZConPropro.Password := edtPassword.Text;
ZConPropro.Database := edtDatabase.Text;
The problem is happening when I try to connect:
ZConPropro.Connected := True;
I selected protocol: PostgreSQL and after postgresql9 and nothing is happening.
I would like to know if someone has this problem and there is some parameter to change.
I'm connecting to this database with HeidiSQL without a problem...same user, password, and database.
You need postgresql client library libpqXX.dll for connection. libmysql55.dll using for MySQL only. Given error message look like MySQL error message. It is said that user xxxx successfully connected to system but it is not authorized to connect this server from localhost. You need to check mysql.user table for user xxxx host config and/or change it. Don't forget run flush privileges after any change.
I am working on Delphi 7, SQL Server 2008 R2 and i am using ADO to connect to database.
My Connection String:
Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=TESTDataBase;Data Source=TestDataSource
when i make my TADOconnection.Connected to True Connectin string is changing it to
Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=TESTDataBase;Data Source=TestDataSource; Use Procedure for Prepare=1;
Auto Translate=True;Packet Size=4096;Workstation ID=MYMachineName;Use Encryption for Data=False;Tag with column collation when possible=False
There are more than 10 applications and i am planning to use the same connection string in all applications.
so when i connect to FirstApplcation i am creating ADO Connection string, saving it in registry or some where so i can use the same connection string for other applications also.
Same user can run more than one application(it can be 2 or 3 or 5 applications).
Here i have 3 questions
1)when i need to share connection?
i mean create the connection string and share the same Connection string(write to registry or some where)
or
create the connection string , connect to database and share the same connection string(write to registry or some where)
2) In my application when i get the shared connection string do i need to connect to database again(TADOConnection.Connected= true)? i think i should connect it again, since it is different application :)
3) For all my applications i open connection at application(main form) form show and i will be closing connection at application(main form) form close.So connection will get close only when application closes and TADOCOnnection.KeepConnection = True. is this create performance issues or burden on database server?
A shared UDL file can be good for sharing a connection. Use the required properties only for your connection string, i.e:
Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security
Info=False;Initial Catalog=TESTDataBase;Data Source=TestDataSource
Don't worry about the extra properties that are added by the ADO after you connect. it's the default properties for the specific provider you use (SQLOLEDB.1). The same properties will be set in all your other applications if you use the exact connection string or UDL file (with a common provider).
ADO connections to SQL Server are pooled by default.
You can simply set e.g.
MyConnection.ConnectionString := 'FILE NAME=c:\my_shared_path\shared.udl';
MyConnection.Open;
A good place to hold a shared connection object (TADOConnection) is in a shared Data Module for the entire application.
Open it in the data module or the main form OnCreate event.
The connection is automatically closed once the TADOConnection is destroyed.
I am using wamp server, it comes with mysql 5.5.16 and I am trying use the mysql from grails 1.3.7. In my Buildconfig.groovy file i have added "runtime 'mysql:mysql-connector-java:5.1.6'" under dependencies and my datasource.groovy looks like this:
dataSource {
dbCreate = "create-drop" // one of 'create', 'create-drop','update'
pooled = true
driverClassName = "com.mysql.jdbc.Driver"
username = "root"
password = ""
url = "jdbc:mysql://localhost:3306/moviestore_dev"
}
but when i refresh dependencies or run the app, i get error=>
:: mysql#mysql-connector-java;5.1.6: not found
I can connect to the database but the data in the database remains as long as the app is running, the next time I run the app, all the data are gone !
I have no idea what is happening, please help !
Thanks
problem is in
dbCreate = "create-drop"
use
dbCreate = "update"
• create-drop: Drops and re-creates the database schema on each application load
• create: Creates the database on application load
• update: Creates and/or attempts an update to existing tables on application load
• [blank]: Does nothing
I'm trying to have a look at the tables generated in h2 db used in Grails project, but something's amiss.
I connect to the browser console at http://127.0.1.1:8082/ but all that's there to browse is INFORMATION_SCHEMA and Users. How do I get tho the tables used/generated by the app?
Just started building out the app and only few domain classes are in place and I'm trying to get a feel for working h2. Prior to that I've been using PostgreSql in all projects so this is very unnerving for the moment.
Thanks in advance
Are you using the right JDBC URL when logging in?
The default in grails is jdbc:h2:mem:devDB.
When an non-existing URL is given, like jdbc:h2:blabla, an empty database is created, with the default INFORMATION_SCHEMA and Users as you described.
Make sure you connect to the URL where your grails application stores its tables. You can find the URL in $GRAILS_PROJECT/config/DataSource.groovy, after the url definition.
environments {
development {
dataSource {
pooled = false
logSql = false
username = "sa"
password = ""
dialect = "com.hp.opr.hibernate.dialect.H2Dialect"
driverClassName = "org.h2.Driver"
dbCreate = "create-drop"
url = "jdbc:h2:mem:devDB;DB_CLOSE_DELAY=-1;MVCC=TRUE"
}
}
}
If you're using 2.0 the web console is enabled by default in dev mode and can be enabled in other environments: http://grails.org/doc/2.0.0.M2/guide/conf.html#databaseConsole
If you're not using 2.0 yet you can install the http://grails.org/plugin/dbconsole plugin or follow the link to my blog post and set it up yourself if you want to customize the url (or if you're using Grails pre-1.3.6 since the plugin has an artificial version restriction to 1.3.6+)
... so in datasource I changed the url to: url = "jdbc:h2:rswDb" (removing the 'mem' part and changing the name of the db). Then 3 db files showed up in the root dir of the project.
Next, in db console set the jdbc url to: jdbc url: jdbc:h2:~/work/web/rsw/rswDb
... and when I hit 'connect' all the tables were there!
Thanks again!