this is the error I get when I'm trying to connect to my local postgresql db:
Cannot connect to database [default]
this is the database configuration. I'm convinced that there is not typo (fat finger error):
db.default.url="postgres://localhost:5432/myproject/"
db.default.user="postgres"
db.default.pass="mypassword"
db.default.driver="org.postgresql.Driver"
db.default.initSQL="SELECT 1"
where is the problem? with pgAdmin I can connect easily
p.s.
I'm using ubuntu. I've noticed that in order to change to postgres user
I must use "su", otherwise it fails changing the current user.
is that has something to do with play! failure to connect my db?
thanks
There might be two things wrong or at least dubious in your setup.
First: The postgres:... URL syntax is not a plain JDBC URL. This format is not understood by the PostgreSQL JDBC driver. See this answer to a similar problem.
Second: You are trying to use the PostgreSQL superuser account for Play. The superuser account should be used only for administrative work, but not "normal" work. Especially not for work which includes public access to the DB via some webfrontend. Any SQL-Injection attack gives the attacker the golden key to your database - including the nuke to wreck your complete DB cluster at once or install any backdoor into you DB server.
So I recommand, that you create a new user which you configure in your Play! settings.
That said: The default password for the postgres user is not set on Ubuntu. This setup allows login to the DB user only from the same OS user. How you can fix this is explained in this answer.
If these two tips don't help: The error you quoted is very vague. There must be more detailed error logs somewhere. Please find them and attach them to your question with the "edit" button.
This is not an answer directly to your question, but I had the same error message and came here via Google. Using Scala Play 2.3, I had
db.default.driver=org.postgresql.Driver
db.default.url="jdbc:postgresql://127.0.0.1:5432/noob_development"
db.default.logStatements=true
which needed to be
db.default.driver="org.postgresql.Driver"
db.default.url="jdbc:postgresql://127.0.0.1:5432/noob_development"
db.default.logStatements=true
I accidentally left the quotes around the driver name out. Now it works perfectly.
here is my conf, it works:
db.default.url="jdbc:postgresql://127.0.0.1:5432/dbname"
db.default.driver="org.postgresql.Driver"
just add the jdbc: before postgresql in db.default.url.
Related
I have been using Oracle cloud PAAS linux server for my DB machine (Oracle 11g) and having linux application server where i can run all my Java applications.
Assume i have spring based web application which can connect cloud DB machine. I have tried to access the schema in Toad for oracle, it is working as expected but when i try to hit the DB for retrieving the data from application it gives below error.
java.sql.SQLException: Io exception: Oracle Error ORA-12650
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:146)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:255)
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:387)
at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:420)
at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:165)
at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:35)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:801)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:154)
at GetConnection.main(GetConnection.java:35)
I have also tried to extend the service access from SID to service name in DB machine. Still give same error. Same code works fine in another cloud machine, which was set by us. But this cloud machine was done by oracle team and most of the things are by default.
Please share your suggestion to fix this issue.
This issue is because of Oracle DB machine encryption ENCRYPTION_SERVER settings. As i understood which is default and set it to enabled, when we set it to disabled or comment the line then application will work as expected. Below is the file name for reference,
Filename : sqlnet.ora (We have to disable ENCRYPTION_SERVER settings)
File Location : ../oracle/product/11.2.0/dbhome_1/network/admin
Hope this helps some one.!
It did not help me at all. Actually I followed your solution and I ended up having another error more critical and serious than the one trying to solve.
Let me explain. First of all the value "disabled" that you mentioned is not even an accepted value for this parameter. According to Oracle (Oracle Docs) these are the accepted values that anyone can use:
SQLNET.ENCRYPTION_SERVER
Purpose
To turn encryption on for the database server.
Default
accepted
Values
accepted: to enable the security service if required or requested by the other side.
rejected: to disable the security service, even if the required by the other side.
requested: to enable the security service if the other side allows it.
required: to enable the security service and disallow the connection if the other side is not enabled for the security service.
Example
SQLNET.ENCRYPTION_SERVER=accepted
In my case being a 12c Oracle Cloud database the default was set to "required" giving me the error "Io exception: Oracle Error ORA-12650" when trying to start my application.
Setting the parameter to "accepted" solved the issue and managed to start my application.
In case you still get the error you can also set the following parameter to accepted:
SQLNET.CRYPTO_CHECKSUM_SERVER = accepted
if you see that in your sqlnet.ora the value is set to "required".
Please have in mind that my application as well as my OCI setup are for testing purposes only and they are not intended to be used in production environment. Setting the value of SQLNET.ENCRYPTION_SERVER and SQLNET.CRYPTO_CHECKSUM_SERVER to "accepted" will significantly lower your Database's security making it vulnerable to any attacks from any application that has access to it. The best case scenario is to modify your application to use the ENCRYPTION as "required".
Downgrading the OJDBC jar to version7 also works - Replace higher version(ojdbc14.jar was the culprit in my case) with ojdbc7.jar in your dependency files
I'm stuck in a huge and old project (j2sdk 1.4.2, Tomcat 4.1.29, MySQL 5.0.51a) that I need to install a new development environment for at work.
I've got a MySQL DB that is accessed by my Tomcat, which treats request from my Java application. In that DB, some tables contain boolean values that are needed by my application.
So, in the application, a prepared statement is made, parameters are added to it, then the request is launched and the result set of this request is stored inside of a custom SQLResult object (that is part of a custom framework made by my company, can't do anything 'bout that - though, it is quite similar to a classic java.sql.ResultSet object).
Here's the problem: when the java application request some data that are stored in the DB as TINYINT(1), those data are returned to the java application as java.lang.Integer, not java.lang.Boolean, as I would like to.
Note: the JDBC connector version used by the Tomcat server is mysql-connector-java-3.0.11-stable.
What I tested so far (without result):
upgrade/downgrade the MySQL connector
added tinyInt1isBit=<true/1> as the end of my connection string
upgrade/downgrade the MySQL DB, always with the same data dump I have been given along the source code
plenty other things I couldn't even remember, because I tested so much things :-/
I'm pretty sure now that the problem comes from the MySQL JDBC connector used by the Tomcat server. Thus, when I changed the version of the connector, nothing else was working anymore (meaning, couldn't even connect a user).
Any ideas?
EDIT: I forgot to precise that, in another part of the java application, request for data stored as DECIMAL are returned as java.lang.String! This is also a major problem I have to solve, but I think the two are linked to the same cause.
From Connector/J documentation
MySQL Type Name: TINYINT
Return value of GetColumnClassName: TINYINT
Returned as Java Class: java.lang.Boolean if the configuration property tinyInt1isBit is set to true (the default) and the storage size is 1, or java.lang.Integer if not.
Please note: or java.lang.Integer if not. Check the property tinyInt1isBit and possibly change it.
If you already did it try to restart the mysql server.
So, after a complete week of work, I managed to found the solution. Beware, that was kind of stupid.
I was right when I thought the MySQL connector was the source of my problems. I decided to retry everything I tried until today to solve the situation, and so I slightly upgraded the connector (from v3.0.11 to v3.1.14). Then I re-launched the problematic DB requests and noticed an ERROR log I didn't see before in my Tomcat logs: the DB name specified was not correct (something like myDB\?autoReconnect=true...). Indeed, a \ had been wrongfully inserted before the connection arguments part.
I removed the guilty \ from the connection string, relaunched my Tomcat, and... tadaaa! My problems were solved!
However, I did test with the old MySQL connector (v3.0.11) and it still returns TINYINT(1) as java.lang.Integer and DECIMAL as java.lang.String. So I guess the client upgraded its MySQL connector on its production Tomcat without warning me.
Anyway, thank you all for your suggestions. Guess I'll read server logs more carefully when I debug in the future :-)
I am new to Oracle, and am trying to run a simple example code with Java, but am getting this error when executing the code.. I am able to start up the listener via CMD and am also able to run SQL Plus. Can anyone give me a hand and tell me what I might be doing wrong?
Update:
I am using JDBC.
Database is local, and I actually had it working but it stopped working just today. I'm not really sure why though. Would you mind giving me some procedures to follow by since I don't know much.
Either:
The database isn't running
You got the URL wrong
There is a firewall in the way.
(This strange error message is produced by Oracle's JDBC driver when it can't connect to the database server. 'Network adapter' appears to refer to some component of their code, which isn't very useful. Real network adapters (NICs) don't establish connections at all: TCP protocol stacks do that. It would have been a lot more useful if they had just let the original ConnectException be thrown, or at least used its error message and let it appear in the stack trace.)
I had the same problem, and this is how I fixed it.
I was using the wrong port for my connection.
private final String DB_URL = "jdbc:oracle:thin:#localhost:1521:orcll"; // 1521 my wrong port
go to your localhost
(my localhost address) : https://localhost:1158/em
login
user name
password
connect as --> normal
Below 'General' click on LISTENER_localhost
look at you port number
Net Address (ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1522))
Connect to port 1522
Edit you connection
change port 1521 to 1522.
done
Another thing you might want to check that the listener.ora file matches the way you are trying to connect to the DB. If you were connecting via a localhost reference and your listener.ora file got changed from:
HOST = localhost
to
HOST = 192.168.XX.XX
then this can cause the error that you had unless you update your hosts file to accommodate for this. Someone might have made this change to allow for remote connections to the DB from other machines.
I figured out that in my case, my database was in different subnet than the subnet from where i was trying to access the db.
I had this error when i renamed the pc in the windows-properties. The pc-name must be updated in the listener.ora-file
Most probably you have listener configured wrongly, the hostname you specify in connection string must be the same as in the listener.
First check the Firewall and network related issues.
Check if Oracle Listener service is available and running. If not you may use Oracle Net Configuration Assistant tool to add and register new listener.
If the above steps are ok then you need to configure Oracle Listener appropriately. You may use Oracle Net Manager tool or edit “%ORACLE_HOME%\network\admin\listener.ora” file manually.
There are 2 options that need to be considered carefully:
Listening Locations associated with the Listener – Hostname(IP) and Port in Listening Location must exactly match the ones used in the connection string.
For example, if you use 192.168.74.139 as target hostname, then there must be Listening Location registered with the same IP address.
Also make sure the you use the same SID as indicated in Database Service associated with the Listener.
https://adhoctuts.com/fix-oracle-io-error-the-network-adapter-could-not-establish-the-connection-error/
IO Error: The Network Adapter could not establish the connection (CONNECTION_ID=iKQM6lBbSLiArrYuDqud8A==)
if you are facing this issue
1- make sure you have downloaded oracle databases like oracle 11g,19c, 21c, or any latest databases.
2- search for services in your computer or type win+r then services.mis then search for oracleservice you will find orcl or xe or any other sid like oracleserviceorcl;
after that you can test your connection using sql developer, sql plus or cmd
To resolve the Network Adapter Error I had to remove the - in the name of the computer name.
In my case, I needed to specify a viahost and viauser. Worth trying if you're in a complex system. :)
For me the basic oracle only was not installed. Please ensure you have oracle installed and then try checking host and port.
I was having issues with this as well. I was using the jdbc connection string to connect to the database. The hostname was incorrectly configured in the string. I am using Mac, and the same string was being used on Windows machines without an issue. On my connection string, I had to make sure that I had the full url with the appending "organizationname.com" to the end of the hostname.
Hope this helps.
Just try to re-create connection. In my situation one of jdbc connection stopped working for no reason. From console sqlplus was working ok.
It took me 2 hours to realize that If i create the same connection - it works.
I am trying, for the first time, to run a java EE 7 web app without an IDE and struggling through the learning curve. To keep things simple I have started with Glassfish 4.1 and Derby 10.11.1.2 which is what I used for development.
My current problem is an error configuring the connection pool on the Glassfish web interface. The error is 'Connection authentication failure occurred. Reason: Userid or password invalid'. However I have ij runing in a dos prompt and the Glashfish web console in Chrome.
from ij I can type 'connect 'jdbc:derby:localhost:1527/databasename;user=username;password=password'; and I connect fine and can look at tables, etc. In the Glassfish web console I have name/value pairs with the same 'user' and 'password' values and it fails (exact same letters & case). I've tried changing the 'databaseName' property to make sure the error wasn't misleading and confirmed it has found the database correctly.
At face value, the error message seems wrong as I have proven from the DOS window. I am sure I am doing something wrong but am lost at how to diagnose it. Any suggestions?
More details of the steps taken: (Although I am sure some of these steps superceed others my lack of success has me in the mindset that redundancy is better than omission - all-in-all it seems much more complicated than it needs to be for a basic setup). My target is Wildfly but Glassfish documentation is better so I figured I would start there.
relevant Windows environment variables:
JAVA_HOME=C:\Program Files\Java\jdk1.8.0_40
DERBY_HOME=%JAVA_HOME%\db
DERBY_INSTALL=%DERBY_HOME%
JAVADB_HOME=%DERBY_HOME%
GLASSFISH=C:\Program Files\Java\GlassFish-4.1
Path=%JAVA_HOME%\bin;%DERBY_HOME%\bin;%GLASSFISH%\bin;%GLASSFISH%\glassfish
CLASSPATH=%DERBY_HOME%\lib\derbynet.jar;%DERBY_HOME%\lib\derbytools.jar;%DERBY_HOME%\derbyclient.jar;%DERBY_HOME%\lib\derbyrun.jar
WILDFLY_HOME=C:\program files\java\wildfly\8.2.0.Final
sysinfo shows all the right paths and versions
Copied many of the derby jars from %derby_home%\lib to %glassfish%\glassfish\domains\domain1\lib\ext per a post by BalusC. I think classpath duplicates this it but can't hurt
Started Domain 'asadmin start-domain' defaulting to domain 1
Started DB by changing directories and using java. Wanted to use 'asadmin start-database --dbhome DB path' but this always started the wrong version. Glassfish and JDK both package derby/javadb and I couldn't figure out how to upgrade Glassfish or start the correct version any other way
cd \users\john\.netbeans-derby (root of the DB created by Netbeans)
Java –jar “%derby_home%\lib\derbyrun.jar" server start
connect browser to 'localhost:4848' to create JDBC connection pool and resource
connection pool: pool name=connectionPool, resource type=javax.sql.DataSource, DB driver Vendor=Derby, introspect was not enabled (found very little documentation to explain what it is) - step 2 was left as defaults
editing connectionPool - enabled Ping on General tab to identify errors, Additional Properties tab: changed User to DB username, left other attributes as default, added... password=db password, databaseName=ClubScoring
errors were presented along the way which prompted setting each attribute. No error was presented for lack of URL but tested steps below with and without URL=jdbc:derby://localhost:1527/ClubScoring
jdbc resources. Added jdbc/ClubScoring, pool=connectionPool => selected and enabled
starting db from correct directory using 'asadmin start-database' does let the application find the correct DB but it crashes since the DB was created with version 10.11.1.2 and this command starts the Glassfish version of 10.10.2.0
Sorry for making this so long but I haven't found anywhere that lays out all of the steps in a simple fashion and figured the details would save time in the long run.
I was dealing with this issue today and found a solution:
https://db.apache.org/derby/docs/10.14/ref/rrefattribsecmech.html
Basically the only security options allowable (as far as 10.14 is concerned) is 3, 4 and 9.
4 is the default and means "Just UserID". You would think this means that as long as a UserID is given, you could connect. But having both set appears to be an issue.
In order to use a (clear text) password and userID, you have to specify 3. It works also if the attribute is deleted or 0 as well but I don't think you get any security that way.
I have created a MySQL database. I am building a GUI in java. How can I connect this Java software to the database?
First, you need to add the mysql jdbc driver jar to your project, then you would create a connection as follows:
String url = "jdbc:mysql://yourhost:port/dbname";
Class.forName ("com.mysql.jdbc.Driver"); // to load the driver
Connection conn = DriverManager.getConnection (url, userName, password);
Here yourhost is the name or ip address of the server, port is the port number to which the mysql server is bound, dbname is the name of your database.
using any of the miriad of Java/SQL API, so you can perform normal SQL queries. JDBC is a start
Start using JDBC, it's best for start. Take a look on some tutorials
http://www.tutorialspoint.com/jdbc/jdbc-quick-guide.htm
http://www.jdbc-tutorial.com/
this post has helped me quite alot!
I'm quite 'disapointed' and 'suprised' I suppose that Java doesn't have the fuctionatly of connected to online databases built in.
One thing that would make it better, and please tell me the followings true: the fact that users of my software don't have to do anything special like install any drivers?
I've already added one answer - asking a question but the comments/reply's I got seem to be a bit off topic and now I've commented back asking for the answer to my original question no one seems to be answering (Have a look for your self - see what I mean)
So, the orignal question :: The only thing I want to know;
Do the users of my software I made using JDBC have to do anything special regarding JDBC, or is just me who needs to have JDBC while writting the program?
PS Sorry if I'm a bit pushy or doing things that your not supposed to do - I'm new to this community!