createSQLException Error while in Configuring Data Source with Weblogic - java

I am trying to configure DataSources with WebLogic 10.3 and database is MySQL Server 5.5 , On entering the following
Driver Class Name ="com.mysql.jdbc.Driver"
url =jdbc:mysql://localhost:3306/weblogicdb
Database User Name =root (User name of Database MySql Server)
Password =123(Password name of Database MySql Server)
Confirm Password =123
and on clicking TestConfiguration, I get the following error.
Connection test failed.
Message icon - Error Unknown database 'weblogicdb'<br/>com.mysql.jdbc.SQLError.createSQLException(SQLError.java:930)
<br/>com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2864)
<br/>com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:806)
<br/>com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:3263)
<br/>com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1176)
<br/>com.mysql.jdbc.Connection.createNewIO(Connection.java:2638)
<br/>com.mysql.jdbc.Connection.<init>(Connection.java:1525)
<br/>com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:260)
<br/>com.bea.console.utils.jdbc.JDBCUtils.testConnection(JDBCUtils.java:505)
<br/>com.bea.console.actions.jdbc.datasources.createjdbcdatasource.CreateJDBCDataSource.testConnectionConfiguration(CreateJDBCDataSource.java:369)
<br/>sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)<br/>sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
<br/>sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)<br/>java.lang.reflect.Method.invoke(Method.java:597)
<br/>org.apache.beehive.netui.pageflow.FlowController.invokeActionMethod(FlowController.java:870)
<br/>org.apache.beehive.netui.pageflow.FlowController.getActionMethodForward(FlowController.java:809)
<br/>org.apache.beehive.netui.pageflow.FlowController.internalExecute(FlowController.java:478)
<br/>org.apache.beehive.netui.pageflow.PageFlowController.internalExecute(PageFlowController.java:306)
<br/>org.apache.beehive.netui.pageflow.FlowController.execute(FlowController.java:336)
<br/>org.apache.beehive.netui.pageflow.internal.FlowControllerAction.execute(FlowControllerAction.java:52)<br/>...
I was looking into many blogs and previously asked questions, where they it could be because of username and password being incorrect. But that is not the issue in my case, I have rechecked it. on using the same username and password, I was able to log into my MySQL database.
Kindly help me in configuring the system.

Error stack clearly says that:
Message icon - Error Unknown database 'weblogicdb'
It seems you have input a wrong database name.
You might be succeeding with username/passwords to MySQL server.
But the server might have multiple databases in it and 'weblogicdb' is not the correct database name you are trying to connect to.
To see what databases the MySQL Server has in it, execute the following command either using java or any other MySQL clients like MySQL command line, SQLyog, PHPMyAdmin etc.
show databases();
This statement should result all the databases available.
Identify the appropriate one for your program and use the same in your code.
To connect through java to execute the above statement, db url should be:
url =jdbc:mysql://localhost:3306/?user=usernamevalue&password=passwordvalue

Related

Is there a difference in the way hibernate connects to db and the way a simple java program does?

I have used the exact same Driver Name, Connection URL , User Name and Password for connecting to my Oracle 11g Express edition database running on my local(same) machine from 2 codes.
Simple Java code to connect to DB and read values from a table.
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con=DriverManager.getConnection(
"jdbc:oracle:thin:#localhost:1521:xe",
"SYSTEM","Platz#123"
);
In Hibernate persistence.xml
The Simple java connection works as expected, However Hibernate gives me the error "java.sql.SQLException: ORA-01017: invalid username/password; logon denied".
Does this has to do anything with the oracle installation configurations on my machine? Or if it is something else.
Could you please provide and explanation and the way out.
I believe the standard JPA property name for the user name is:
javax.persistence.jdbc.user
Not:
javax.persistence.jdbc.username

How to create JDBC data source in Oracle WebLogic server properly?

I'm trying to create a JDBC data source in Oracle WebLogic server and getting some error. I can log in the web console http://localhost:7001/console using user name + password and I followed the Youtube video / tutorial page - Configuring a JDBC data source as same.
I have a wireless connection and I get the Host name (# 12 in the tutorial ) by typing
ipconfig getifaddr en0
in the Mac OS terminal. It returns 10.131.173.138 ( the same format, I changed three random digits ) and I put it inside the Host name and also filled up all other information's. However, after that when I'm trying to test the set up by clicking Test Configuration, it returns me the following errors that I provided below -
Connection test failed.
Message icon - Error IO Error: The Network Adapter could not establish the connectionoracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:800)oracle.jdbc.driver.PhysicalConnection.connect(PhysicalConnection.java:793)oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:33)oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:614)weblogic.jdbc.common.internal.DataSourceUtil.testConnection0(DataSourceUtil.java:340)weblogic.jdbc.common.internal.DataSourceUtil.access$000(DataSourceUtil.java:22)weblogic.jdbc.common.internal.DataSourceUtil$1.run(DataSourceUtil.java:254)java.security.AccessController.doPrivileged(Native Method)weblogic.jdbc.common.internal.DataSourceUtil.testConnection(DataSourceUtil.java:251)com.bea.console.utils.jdbc.JDBCUtils.testConnection(JDBCUtils.java:751)com.bea.console.actions.jdbc.datasources.createjdbcdatasource.CreateJDBCDataSource.testConnectionConfiguration(CreateJDBCDataSource.java:479)sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)java.lang.reflect.Method.invoke(Method.java:606)org.apache.beehive.netui.pageflow.FlowController.invokeActionMethod(FlowController.java:870)org.apache.beehive.netui.pageflow.FlowController.getActionMethodForward(FlowController.java:809)org.apache.beehive.netui.pageflow.FlowController.internalExecute(FlowController.java:478)org.apache.beehive.netui.pageflow.PageFlowController.internalExecute(PageFlowController.java:306)org.apache.beehive.netui.pageflow.FlowController.execute(FlowController.java:336)...
I think it mainly says The Network Adapter could not establish the connection
However, I don't have much knowledge what to do to establish the connection properly. Thanks.
You need a real database with correct values in the jdbc URL:
i.e.
For example, if the database to which you want to connect resides on host prodHost, at port 1521, and system identifier (SID) ORCL, and you want to connect with user name scott and password tiger, then use either of the two following connection strings:
Using host:port:sid syntax:
String connString="jdbc:oracle:thin:#prodHost:1521:ORCL";

jdbc.SQLServerException: Login failed for user for any user

I trying to test the connection with my local sql DB. I have this code:
try{
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance();
DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=SocialFamilyTree;user=SOSCOMP");
}catch(Exception e){
System.out.println("Couldn't get database connection.");
e.printStackTrace();
}
I tried many users. my windows user is SOSCOMP and doesn't have a password. I also know that SQL 2008 create users as "sys" "dbo", I tried these too. I'm always getting:
Couldn't get database connection.
com.microsoft.sqlserver.jdbc.SQLServerException: Login failed for user 'SOSCOMP'.
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:196)
at com.microsoft.sqlserver.jdbc.TDSTokenHandler.onEOF(tdsparser.java:246)
at com.microsoft.sqlserver.jdbc.TDSParser.parse(tdsparser.java:83)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.sendLogon(SQLServerConnection.java:2532)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.logon(SQLServerConnection.java:1929)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.access$000(SQLServerConnection.java:41)
at com.microsoft.sqlserver.jdbc.SQLServerConnection$LogonCommand.doExecute(SQLServerConnection.java:1917)
at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:4026)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1416)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:1061)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:833)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:716)
at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:841)
at java.sql.DriverManager.getConnection(DriverManager.java:579)
at java.sql.DriverManager.getConnection(DriverManager.java:243)
at FT_Receiver.FT_Receiver.main(FT_Receiver.java:12)
Any ideas?
Thanks
If you try to connect with database which is using windows authentication, you can use 'integratedSecurity' option in your connection string.
DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=SocialFamilyTree;integratedSecurity=true;");
Having been through this very recently the steps I took to solve pretty much the same problem were
use SQL Server Management Studio to log in with the desired account and confirm access to read (and write if necessary)
Use SQL Server Configuration Manager to confirm that the server instance is listening on the IP address being targetted
Disable the firewall to check that isn't getting in the way (and add an exception if necessary for future use)
The absolute kicker for me was understanding what IP addresses and ports the instance was set to listen on so that when I constructed the connection string the connection wasn't being rejected.
Also, if you want to connect using Windows logins you need to ensure the SQL instance is configured for mixed mode authentication (i.e. to allow Windows and SQL logins)
Since you get this error,the Sql server correctly listens to the port.
Open Sql Server Management Studio connect to your Server.
right click on the server's icon and choose properties.
Go to the security tab and tick Sql Server and Windows
Authentication mode.
If you want to define a user,go from the tree, to Security->Logins,right click on logins folder and click "New Login".
Now your server should work with this Url String.
Use the log file of the Server that may help you understand its working.
Re: Did it. still WARNING: Failed to load the sqljdbc_auth.dll cause :- no sqljdbc_auth in java.library.path – Mike Oct 7 at 14:03
you have to add the path to sqljdbc_auth.dll by adding this under VM arguments in Eclipse or commandline if you're running from the shell:
-Djava.library.path="\MS SQL Server JDBC Driver 3.0\sqljdbc_3.0\enu\auth\x86"
that's if you're running 32 bit Windows. else the final subdir changes accordingly.
I think this might be a better answer though, to setting up SQL Server user based authentication:
Connecting SQL Server 2008 to Java: Login failed for user error
(I try to summarize it here: http://silveira.wikidot.com/sql-server)
I also faced the same issue, In my case the following things are configured wrongly
Two SQL (versions) servers are running in my system --> Sol: Please check ourselves which server we are pointing.
Ports are configured as dynamic --> Sol: we should set port 1433 and dynamic port should be 0, if we are connected to specific port.
While creating the new login (user) I have selected the option " change password after first login "--> Sol: we should not select this option while creating the new login, if we are trying connecting from some other service like Openfire.

HSQLDB server mode username/password

If I start the HSQLDB in server mode using my Java code, the server starts without any problem. However, when I try to connect to the same either through the Java code or through the HSQLDB DatabaseManagerSwing; I am unable to connect.
I started the server with user=conn1 and password=conn1 in memory-only mode. But when connecting to the server it gave me following exception:
java.sql.SQLInvalidAuthorizationSpecException: invalid authorization specification - not found: conn1
I can only connect by giving user=SA and blank password. I am using HSQLDB 2.2.5 and JRE1.7 on Windows7 machine.
Can someone tell me where am I doing wrong?
If you try these server properties with recent versions of HyperSQL, you will probably get an error message as your server properties are not correct. The properties "server.username" and "server.password" are not valid. And the dbname.0 property must be in lowercase.
If you want to create a server database with a user name other than SA, you can append the user and password to the database path:
server.database.0 = file:E:/DB/myDB;user=testuser;password=testpw
server.dbname.0 = mydb
After the server is shutdown, there is no need to include the user and password. The credentials are used only to create the database. After that, the credentials are checked when a connection is made to the server.
2020 update with additional information due to recent questions in comments:
The user name and password specified for database.0 are taken into account only when a new database is created by starting the server. If the database files exist before starting the server, user name and password are unnecessary and are simply ignored.
Other settings for a new database, such as hsqldb.tx=mvcc, can be appended to the database.0 string.
You must have properties for database.0 for your server. You can add properties for database.1 if your server is serving two different databases.
The file path specified for database.0 is hidden from the users that connect to the server. Only the dbname.0 value is used for access, for example:
DriverManager.getConnection("jdbc:hsqldb:hsql://localhost/mydb;uer=testuser;password=testpw")
In the getConnection call, it is better to state the user and password separately to keep the code clear:DriverManager.getConnection("jdbc:hsqldb:hsql://localhost/mydb", "testuser", "testpw")
See the Guide http://hsqldb.org/doc/2.0/guide/dbproperties-chapt.html for all the details.
Appears the problem you were running into (at least initially) is that, for HSQL in memory databases, if it's the "first" in memory database (i.e. process just started), the username "has to be" sa (username "sa" is not case sensitive, or it can be empty username, which implies the "default" which is also sa). You can use a blank password, or specify a password. Based on some trial and error, if you want to reconnect to the same (in memory) DB later, you'll have to re-use the same password (blank or otherwise). If you want to use a user other than SA you'd probably have to first connect to your database using SA and execute some "create user" type commands to create new users. Then reconnect using that user (assuming your DB is all in memory).
You can use multiple different in-memory databases (if that's what you're trying to accomplish by specifying a different user) like this:
// change the MySpecialTestDb String for multiple different in memory databases
// or reuse the same value
// to reconnect to a previously created in memory database [i.e. within the same process previously].
String DB_CONNECTION_STR = "jdbc:hsqldb:mem:MySpecialTestDb";
String DB_USERNAME_STR = "sa";
String DB_USERNAME_PASSWORD = "";
DriverManager.getConnection(DB_CONNECTION_STR, DB_USERNAME_STR, DB_USERNAME_PASSWORD);
Each new database you create follows the same system (it must be initial user SA and "adopts" whatever first password you give).
ref: http://www.hsqldb.org/doc/1.8/guide/guide.html#advanced-chapter
Or if you want to just "reset" an in memory database, like between each unit test, see here.
Note that documentation also says "...This feature [default user SA] has a side effect that can confuse new users. If a mistake is made in specifying the path for connecting to an existing database, a connection is nevertheless established to a new database. For troubleshooting purposes, you can specify a connection property ifexists=true ..."
Point no 1) Whenever you create a DB, you have to specify the username and password. You can keep it both blank; But same username and password has to be used while connecting to server.
If you observe script file of your DB, you can see commands like :-
CREATE USER "usr" PASSWORD DIGEST '9003d1df22eb4d3820015070385194c8'
ALTER USER "usr" SET LOCAL TRUE
GRANT DBA TO "usr"
I had created DB with user name "usr" so it appeared in script file in those commands. Now while starting server I do not need to specify user name or password. It will IGNORE this information.
While connecting server you have to give exactly same username and password, you gave while creating DB.
Point no 2)
Make sure that there is no space in path of your DB files. If there is space then enclose the whole path in double quotes.
I struggled a lot to find out this silly mistake of mine.
Now if I start the server wil below command it starts correctly
1) Go to lib of HSQL
cd C:\Users\owner\Documents\Java Project\hsqldb-2.2.9\hsqldb\lib
Then give command
java -cp hsqldb.jar org.hsqldb.Server -database.0 file:"C:\Users\owner\Documents\Java Project\hsqldb-2.2.9\TmpDBLocation\myKauDB" -dbname.0 xdb
2) In other command prompt went to lib location
cd C:\Users\owner\Documents\Java Project\hsqldb-2.2.9\hsqldb\lib
Then connected the Swing UI of HSQL DB by giving command in other command prompt window
java -cp hsqldb.jar org.hsqldb.util.DatabaseManagerSwing --driver org.hsqldb.jdbcDriver --URL jdbc:hsqldb:hsql://localhost/xdb --user "usr" --password ""
In my brand new 2.3.2 installation, after clicking bin/runServer.bat, I managed to connect (with Squirrel) using:
URL: jdbc:hsqldb:hsql://localhost:9001
User: SA
Password: <blank>

Connecting to local instance of PostgreSql with JDBC

I have a running local instance of PostgreSql on a linux machine. When I use psql command from the shell I success to log in without any problem. I need to connect to the PostgreSql via the JDBC, but I don't know what exactly should I pass as url parameter to DriverManager.getConnection().
It should start with jdbc:postgresql: but what's going next?
I was told by the system group that a database with was created like user name. e.g. if my user is jutky a db named jutky was created, but when I try to open a connection to jdbc:postgresql:jutky I get an error
org.postgresql.util.PSQLException: FATAL: password authentication failed for user "jutky"
:(
Additional info
When I login via the psql I'm not prompted for the password, so when I try to login via JDBC I pass an empty string as a password - is it correct, or should I pass null or something?
When I type psql --help in the shell I see among the rest this line:
Connection options:
-h, --host=HOSTNAME database server host or socket directory (default: "/var/run/postgresql")
So I understand that I connect to PostgreSql via a socket directory, does that matters something to the URL string in the JDBC?
EDIT
First thanks for the answers.
Second: its not first time I'm using JDBC and in particular not the first time I'm connecting to the PostgreSql from JDBC, so I know the general rules and I have read the documentations. However in the described case I'm not sure how exactly should I construct the connection string if the instance is running via the socket directory and what password should I provide. Because when I login via the psql I'm not prompted for password at all.
Thanks in advance.
In addition to other answers note that by default Postgres is configured to accept connections via Unix sockets with authentication based on your operating system account, that's why psql works fine and doesn't require the password.
JDBC connections are made over TCP/IP with password authentication, so you need to modify pg_hba.conf accordingly. For example, this line allows TCP/IP connections from the same machine to all databases for all users with password authentication:
host all all 127.0.0.1/32 md5
After adding this line jdbc:postgresql:databasename should work.
EDIT: You can't create a JDBC connection over Unix socket since PostgreSQL JDBC driver can only work over TCP/IP. The password you use when creating JDBC connection is the password assigned to your user. If you don't have it, you can assign it, for example, using ALTER USER command. See 19.3. Authentication methods.
See also:
19.1. The pg_hba.conf file
It's all explained in official documentation.
This is the relevant part:
String url = "jdbc:postgresql://localhost/test?user=fred&password=secret&ssl=true";
Connection conn = DriverManager.getConnection(url);

Categories

Resources