Using the embedded driver I can connect to my derby database using the JDBC url:
jdbc:derby:mydbname
But, I usually put the full path for the db like:
jdbc:derby:/Users/oreyes/dbs/mydbname
Is there a way I can just specify the db name and have something like a "db_path" or something like that?
I'm not an expert with derby, setting derby.system.home as described in developers guide seems to work as you expect.
Related
I'm using Spring Boot and JDBC for my database connection. I placed schema.sql at the classpath to initialize a schema and tables.
Because the schema doesn't exist yet while connecting to the datasource, I have to configure the datasource in application.properties like so:
spring.datasource.url=jdbc:mysql://localhost:3306/
schema.sql:
CREATE DATABASE IF NOT EXISTS <schema_name>
USE <schema.name>;
CREATE TABLE...
So I select the schema after creating it. This obviously doesn't persist for too long.
How do I configure this properly? Is there a way to select a default schema after the create script or maybe change the datasource url?
With JDBC you need to use Connection.setCatalog to switch between databases. You should not use USE <databasename> as the JDBC driver itself needs to be aware of which database it is operating on.
Based on your code from the schema.sql
USE <schema.name>;
This will not work for your java environment. The schema.sql will be executed and finished, which will not cater your requirement to set the default schema.
The General approach will be to use JDBC URL as;
jdbc:mysql://localhost:3306/DB_NAME
This will set the default db as DB_NAME.
Assumptions: I am assuming that you want to connect to single node DB without any loadbalancer or failover mechanism to be used. URL may change based on these features to be configured.
If you are not specifying the DB_NAME in the URL, it means their is no default schema.
You have 2 options to access the DB in that case.
1) Always use the Connection.setCatalog() method to specify the desired database in JDBC applications, rather than the USE database statement.
2) fully specify table names using the database name (that is, SELECT dbname.tablename.colname FROM dbname.tablename...) in your SQL. Opening a connection without specifying the database to use is generally only useful when building tools that work with multiple databases, such as GUI database managers.
For more details refer to the below mysql portal for reference.
https://dev.mysql.com/doc/connector-j/en/connector-j-reference-configuration-properties.html
I am creating a Hibernate project in IntelliJ IDE and trying to hook it up with a H2 database. I created the project based upon this tutorial:
http://www.roseindia.net/hibernate/hibernate4.2/hibernate-example-step-by-step-in-eclipse.shtml
The only change I'm making is the database, instead of MySQL, I'm using H2. However, when I'm trying to run the application, the insertion to the database is shown to have been successful, but there are no signs of any such rows when I open up the database in the H2 console. I've tried many solutions suggested here and elsewhere, including this, this and this. I've tried changing the connection URL of the database in the hibernate.cfg.xml file from a relative path to absolute path, but to no avail. I'm attaching a screenshot of my hibernate.cfg.xml and the relevant portion of the log below. Please help me out with this.
your hibernate.connection.url should be something like that jdbc:h2:tcp://localhost/mem:playground I am assuming you are starting the H2 database out of your project, as you are connecting to H2 via console.
There's very little information about DbSetup so I couldn't find an answer to this question anywhere else.
I need to test Data Access Layer and decided to use DbSetup for it. I tried to use DbSetup user guide this example just to see how it works but I get such exception:
com.ninja_squad.dbsetup.DbSetupRuntimeException: java.sql.SQLException: No suitable driver found for 127.0.0.1:3306
My database is MySQL Server.
What could be the problem?
Your URL is incorrect. JDBC URL for MySQL looks like
jdbc:mysql://localhost:3306/databasename
as described in the documentation.
And of course, the jar of the MySQL JDBC driver must be in the classpath.
I created a JDBC application using mysql5.5.14 .
I want to run it on other systems without mysql5.5.14.(but having java)
Is thee any way i can install(and configure) mysql5.5.14 on other systems via my application.
I'm not entirely sure what you're trying to do, but if you mean "configure" as in "create the same database tables and views", you can use something like Liquibase.
If you want to keep using JDBC but with another database system at the backend, you can just pass the JDBC driver's class name to the program through a configuration file and load the driver using
Class.forName(jdbcDriver)
when you start up your application.
HTH
Raku
what is the service name of oracle10g xe database
It varies ragarding the network. In our local system it'll be 'localhost'
The jdbc url for a locally installed xe databse would look like this: jdbc:oracle:thin:#127.0.0.1:1521:XE, note that XE is the SID, a service name does not seem to be needed for jdbc.
Service name is ambigious. But as you asked about jdbc I guess you need advice on the service name that is used on the jdbc url.
Here is a good article with a link to oracle sources.
Basically it says that the format is
jdbc:oracle:thin:scott/tiger#//myhost:1521/myservicename
and myservicename can be found in TNSNAMES.ORA.