How to create a database in oracle and its url? - java

I was using MySQL for my application. And i was using hibernate in my spring mvc application.
So all the tables are automatically created in my databse (MyApp).
I wrote a command
create database Myapp
in Mysql command prompt.
And when i ran my application, all the tables were created automatically inside Myapp.
In my hibernate config file , to connect to Mysql i have used the following url
jdbc:mysql://localhost:3306/Myapp
But now i want to change my database client to Oracle.
But i have seen in oracle the URL is given as
jdbc:oracle:thin:#localhost:1521:xe
So the database is not mentioned in the URL?
And also the command i wrote to create database in Mysql is not working in oracle.
How i can do this?

Following table lists down popular JDBC driver names and database URL.
RDBMS JDBC driver name URL format
MySQL com.mysql.jdbc.Driver jdbc:mysql://hostname/ databaseName
ORACLE oracle.jdbc.driver.OracleDriver jdbc:oracle:thin:#hostname:portNumber:databaseName
DB2 COM.ibm.db2.jdbc.net.DB2Driver jdbc:db2:hostname:port Number/databaseName
Sybase com.sybase.jdbc.SybDriver jdbc:sybase:Tds:hostname: port Number/databaseNam

So the database is not mentioned in the URL?
It is mentioned. In your example jdbc:oracle:thin:#localhost:1521:xe, **xe** is the database service name similar to Myapp in your MySQL example.

Try to read the following links below
http://www.mkyong.com/jdbc/connect-to-oracle-db-via-jdbc-driver-java/
http://www.rgagnon.com/javadetails/java-0112.html
and download the drivers here and i think it contains some examples for you
http://www.oracle.com/technetwork/database/features/jdbc/index-091264.html
and for creating the database please watch this tutorial video
http://www.youtube.com/watch?v=3ZQ9ihJYRyM

Related

H2 tables not showing up in IntelliJ for Jhipster generated project

So I generated a new Spring boot application using jhipster. Upon navigating to the H2 console, the following information is shown.
I am able to login, and I can verify tables exist.
Next, I copy the link, jdbc:h2:file:./target/h2db/db/ikdoemee and try to connect to the H2 database using IntelliJ which shows successful.
However, the IntelliJ database view isn't showing any tables.
I tried adding the following parameters to my JDBC url, but no tables show up.
jdbc:h2:file:./target/h2db/db/ikdoemee;AUTO_SERVER=TRUE;DB_CLOSE_DELAY=-1 ;DATABASE_TO_UPPER=false
Why am I unable to get my tables visible in IntelliJ?
My .h2.server.properties is
#H2 Server Properties
0=JHipster H2 (Disk)|org.h2.Driver|jdbc\:h2\:file\:./target/h2db/db/ikdoemee|ikdoemee
webAllowOthers=true
webPort=8082
webSSL=false
EDIT: My target folder:
You need to activate h2 "Automatic Mixed Mode" by changing the spring.datasource.url of the application-dev.yml file.
example URL: jdbc:h2:./target/h2db/db/'PROJECTNAME';AUTO_SERVER=TRUE
The URL for the connection to the h2 database should look like that:
jdbc:h2:/home/'USERNAME'/IdeaProjects/'PROJECT'/target/h2db/db/'PROJECTNAME';AUTO_SERVER=TRUE
if that doesn't work try also to delete the target folder and refresh the h2 connection
To resolve this issue I installed Buddy JPA plugin.
It created profile automatically and I compared it with mine.
the difference was in parameter DB_CLOSE_ON_EXIT=FALSE
I tried it with manually created profile and it works as well.
The result link is:
jdbc:h2:file:./work/h2db;DB_CLOSE_ON_EXIT=FALSE
The only solution that worked for me at the moment is to put the direct path to the file in Path field without extension.
After that I could see my tables in IDEA.
click to preview settings
Note:
Don't forget to also add parameter AUTO_SERVER=TRUE to datasource.url, as pointed out by #Unknown_Energy.
My apps versions:
Idea 2018.3.5 UE
h2 1.4.197
h2 base name: demo.mv.db
this bug is related to these issues:
Data Source detection
Intellij IDEA and H2 DB file recognition problem
When running the application, the log will show something like
n.w.config.DatabaseConfiguration 1: H2 database is available on port 18080.
Then change Connection Type to Remote and port to the port just showed,
append the db file location to the url (with out extension) just like ./build/h2db/db/projectname, User will be the ProjectName.
The final url will like jdbc:h2:tcp://localhost:18080/./build/h2db/db/projectname
This worked for me, I'm not a English native speaker, sorry for my poor English.

Java DB (Embedded) connection cannot find database

I am trying to create a connection using Java DB (Embedded), but I keep getting the error shown in the image below:
If it helps my Java DB Installation path is: C:\Program Files (x86)\glassfish-3.1.2.2\javadb and my database location is: C:\Users\MyPC\.netbeans-derby
I have tried specifying the file paths, I have watched YouTube tutorials and tried a few examples from Oracle and other sites, none of which help.
The properties (if it helps) for this database are:
I noticed that the driver class is ClientDriver, is it posible this could be playing a role in the problem?
How can I get the Java DB (Embedded) connection to work (or simply correct the problem)?
The root directory doesn't load, find the location on the Database,
eg C:\Users\xxx.netbeans-derby\dataBaseName
copy it and paste it as the database Java DB(Embedded) name. Your new JDBC URL: is now jdbc:derby:C:\Users\xxx.netbeans-derby\dataBaseName
Test the connection and the path should connect.
I think this is a bug in 8.1 and needs to be addressed, but this will work around it.

How to export a java project with a database ( connected to sql server ) for using in different computers?

I'm new in working with databases and connecting java to sql server. I just created a database and a java application for it. I used the sqljdbc4.jar file in my library and all the stuff required to connect the app with the database, but I want to know : what do I need to export so someone in an other computer can use that application and have that database in that computer, without having installed sql server or something, what do I need to do ?
It depends on what you want to do. If you want them to connect to a databse via your app, then you will have to allow them to access the database via your application by providing the privileges. If you want to bundle the whole database with your java code, then you need to use an in application database like h2 http://www.h2database.com/html/main.html. There are alternatives like derby and hsql db, but h2 is better than that. See the comparison on the h2 homepage.

Does jdbc support persian language

I designed a java desktop application using jdbc technology to connect to mysql database.
But when I want to store a data in my db which is in persian language it saved like some ????
I tried creating the database with both
CREATE DATABASE 'db' CHARACTER SET 'utf8';
and
CREATE TABLE `Table1` (
[...]) DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
I tried every other COLLATEs but they seem not working properly.
What should I do?
Make sure the driver properties are set. Check that useUnicode is true, characterEncoding is "UTF-8". I assume you are using the Connector/J JDBC driver.
Refer to this answer.
A brief version of what the answer says is that you should add
?useUnicode=true&characterEncoding=UTF-8
To the end of JDBC connection URL.
For example:
jdbc:mysql://localhost:3306/db_name?useUnicode=yes&characterEncoding=UTF-8

Table view does not exist exception on Netbeans Derby connection

I followed the instructions in this blog to create a basic embedded database application.However, although checking the steps over and over and searching for the problem on the web , I'm still getting the exception : Table view blabla does not exists. Table seems to exists when I expand my driver's app schema. Netbeans version is 7.3.
The most common reason for a table-does-not-exist error with Derby is confusion over the location of the database. The database that you are accessing via Netbeans is probably different than the database that your application is accessing.
The location of your database is controlled by the JDBC connection URL, so if you provide some details about your JDBC connection URL, that might help others to help you.

Categories