jdbc programming through oracle - java

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.

Related

How to create a database if it does not exist with springboot/JPA and SQL Server?

I am surprised I haven't found an SO question that answers this. I am trying to connect a springboot/JPA application to an SQL Server on my local machine. I have the application setup so that it can connect to a database if it it exists, but if I change the JDBC URL to create the database if it doesn't exist then it fails. Here is what the properties look like when it fails.
spring.jpa.hibernate.ddl-auto=update
spring.datasource.url=jdbc:sqlserver://localhost:1433;databaseName=testing;createDatabaseIfNotExist=true;
spring.datasource.username=hello
spring.datasource.password=Hello1234
spring.datasource.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver
spring.jpa.database-platform=org.hibernate.dialect.SQLServer2008Dialect
spring.jpa.show-sql=true
Here is a snippet of the error I receive when starting the app:
com.microsoft.sqlserver.jdbc.SQLServerException: Login failed for user
'hello'. ClientConnectionId:971a3369-258b-4713-bddc-cda559b9fe94 at
com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:262)
~[mssql-jdbc-8.4.0.jre11.jar:na] at
com.microsoft.sqlserver.jdbc.TDSTokenHandle
If anybody has any thoughts as to how I can change this so the database is created if it does not exist I would be very thankful. Thanks in advnace.
I don't think a database can be created using JPA.
It has to be created manually or in some other ways, but JPA won't do that for you.
And it would be a bad practice as well to create the database using the application itself, and the use of same credentials.
Yes, definitely you can auto-create a database with JPA for that
spring.datasource.url=jdbc:sqlserver://localhost:1433;databaseName=testing;
createDatabaseIfNotExist=true;
line should be changed to:
spring.datasource.url=jdbc:sqlserver://localhost:1433
/testing?createDatabaseIfNotExist=true
In practice your application should never create your database so its not really a problem most of the time(Outside small databases like sqlite3). Different databases would handle this situation differently as well.
In your case I do not see this as a valid jdbc parameter in the documentation.
I would recommend creating the database in advance with a privileged user separate from your application user.

DbSetup simple example, SQLException occurs

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.

Glassfish JDBC: Do I have to use only jdbc/__default?

I try to use Glassfish/MySQL. I have created JDBC resource and JDBC connection pool for MySQL.
But if I tried to put MySQL JDBC resource in jta-data-source, nothing works.
Then if I tried to modify jdbc/__default and change its connection pool from DerbyPool to MySQL, it works. My entity gets persists to the correct table.
So do I have to use jdbc/__default only as my JDBC resource for my app? How can I use the JDBC resource and JDBC connection pool I created in my app?
I really have hard time understanding how to use JDBC in Glassfish.
This is my first time to ask question in this forum. Thank you very much.
See this link for a step by step tutorial on how to create JDBC connection pools in Glassfish server. Here is the official documentation on how to do it. Or you can read this SO question. And another resource that you can use is this SO question.

JavaDB ( derby ) path to database?

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.

JDBC Realm: GlassFish v2.1 = OK; GlassFish v3 = fail with invaliduserreason

In my J2EE 5 application I have a JDBC Realm based security with Form method. Encrypt method is MD5 as default.
The database is PostgreSQL 8.4 installed locally (or 8.3 available via lan).
My app used to work finely on GlassFish v2.1 server with PostgreSQL 8.3, but now I need to deploy it on GlassFish v3.
I am absolutely sure I have done all the same config on GFv3 like creating Connection Pool (which pings with no problem), JDBC Resource and JDBC Realm.
But on GFv3 I get login exception with "invaliduserreason" while the database schema is just created from the working database script.
I have checked the data and entered login/password thousand times and it seems that data is all right.
So where can I find the reason of unworking security? Please, advice.
NetBeans 6.8
Thanks.
I had the same issue here.
I resolved setting the security log to finest.
I saw that jaas was querying the db in lowercase even though I used a camel notation in naming my fields in postgresql table.
The only solution I found was to name all my table and fields in lowercase in Postgresql server as well.
You might want to increase the logging for the security system. Go to Logger Settings -> Log Warnings and set logger name 'javax.enterprise.system.core.security' to trace. Try again and check the logs.
Try changing database tablenames to UPPERCASE. I had the exactly same problem as you have and changing tablenames to uppercase solved the problem for me.
Setting Digest Algorithm to "none" worked for me. I am using Glassfish 3.1 with Derby. In realm config i have name of tables in lowercase and userid and groupid are columns in the same table, so these things do not cause problems on Derby.
Here is a nice article about jdbc security realm in glassfish and how to configure it: http://jugojava.blogspot.com/2011/02/jdbc-security-realm-with-glassfish-and.html
try adding database name to the property Url in your connection pool.. the sqlexception hidden here states that database name is not specified.. worked for me

Categories

Resources