I have an application that connects to a Derby database using the Derby Network Server that has been started as a standalone process outside of the Netbeans IDE.
When I run my application within the IDE (I don't start the Network Server from the Services tab as it is already running) the following is observed:-
The application connects successfully to the server.
Subsequent database accesses fail with error Internal Exception: java.sql.SQLNonTransientConnectionException: The connection was refused because the database MyAppDB was not found.
Error Code: 40000
The persistence.xml in Netbeans shows the following for the JDBC connection:-
jdbc:derby://localhost:1527//Users/David/Desktop/DerbyDatabases/MyAppDB
[david on TEST]
However the xml source in Netbeans shows the following:-
jdbc:derby://localhost:1527/MyAppDB
I can fix this problem by changing the persistence.xml source (in Netbeans) to show the following for JDBC connection:-
jdbc:derby://localhost:1527//Users/David/Desktop/DerbyDatabases/MyAppDB
Everything now works and the application runs fine :-)
HOWEVER!!!
As soon as I tell Netbeans to do a Clean and Build Project, it reverts the JDBC connection back to:-
jdbc:derby://localhost:1527/MyAppDB
On running the Application it can no longer access the Db with the same error as above.
Note that none of these problems occur if I run the Network Server from with Netbeans by opening the connection via the Services tab. This is no good for me as I want to deploy the application.
Do any of you guys know what is going on here? - I'm sure it's a simple mistake on my part.
Thank you.
This problem was eventually solved by deleting the persistence unit (using NetBeans) and re-creating it with the same name but with the JDBC connection containing the correct path. Is this a NetBeans problem?
Related
I try to connect my Springboot application to my local MSSQL Server with hibernate. For now I've set up a local ms sql server. I couldn't establish a connection to my database using IntelliJ CE and the JPA buddy.
On the net I found a guide that used IntelliJ UE. I installed the 30 day trial and with the ultimate version I could establish a connection with the database (using View->Tool Windows->Database, SSL is not enabled).
Even though the URL is kinda messy with "...server://./db". If I replace the '//./' with '//localhost/' it does not work anymore.
Now, I soon won't have access to the ultimate version anymore. So, my question is: How do I get the same behaviour with the JPA buddy and IntelliJ Community Edition?
I guess that it is related to the selected driver 'MS SQL Server ->LocalDB<-'.
When I use the following JPA settings, it does not work in the community version (it doesnt matter if I use the 'jtds' driver or not):
In both cases I get "Error during login for the user 'dbuser'". (The server is local and I don't have SSL enabled, therefore the ';encrypt=false')
I also tried to use the application.properties with the following content:
spring.datasource.driver-class-name=com.microsoft.sqlserver.jdbc.SQLServerDriver
spring.datasource.url=jdbc:sqlserver://localhost;encrypt=false
spring.datasource.username=dbuser
spring.datasource.password=...
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQLDialect
spring.jpa.hibernate.ddl-auto=update
But this didn't work either.
Any help is appreciated.
I am trying to run a simple java web app that connects to a back end DB2 database(IBM dashdb) to get retrieve some data.
I am getting a weird error message when I try to run this application on a ubuntu hosted tomcat 8.5.
I managed to get this application running on a tomcat v8 hosted on Windows.
The actual error message is:
No suitable driver found for jdbc:db2://yp-dashdb......
I don't really understand why this is happening because I have the db2jcc4. in my web-inf\lib folder.
I thought it was something wrong with the library so I created a separate Java app to simply connect and retrieve some data from the database. That one works just fine with the same library.
This is the code used to set up the connection (I trimmed out some of the details).
private Connection conn = null;
conn= DriverManager.getConnection("jdbc:db2://yp-dashdb...");
Keep in mind, that this exact same code works in a Standard Java app so the connection details work and there's no typo in the connection info.
Is there something obvious that I'm overlooking here?
After spending some time trying to figure this one out I find out the problem. My drivers were not being registered by DriverManager. The quick fix I found for this was to manually register it before trying to load the driver.
DriverManager.registerDriver(new com.ibm.db2.jcc.DB2Driver());
This has solved my issue. The way I found out about this was to print out all the registered drivers and print them out. Not the most elegant solution but it helped me find out what I'm missing.
/*
System.out.println("checking for drivers");
Enumeration<Driver> myDrivers = DriverManager.getDrivers();
System.out.println(myDrivers.hasMoreElements());
while(myDrivers.hasMoreElements()){
System.out.println(myDrivers.nextElement().toString());
}
*/
WEB-INF/lib is in your application. It might be so that tomcat needs this driver before your app is loaded? Try putting it into the tomcat's lib folder and restarting...
Here is another question on the same topic: Why must the JDBC driver be put in TOMCAT_HOME/lib folder?
I am running my java web application on glassfish server v4.1 in netbeans v8.0.2, using sqljdbc42 and this connection code-
Connection connection;
String url = "jdbc:sqlserver://localhost:1433;databaseName=Lista;integratedSecurity=true";
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
connection = DriverManager.getConnection(url);
When i open my ide and run my project for the first time the glassfish server starts automatically since my project's server is glassfish, and i can perform any crud operation with my Ms-Sql server2012.
But the problem starts when i make changes in any file keeping the server on and run the project again and try to perform any crud operation i get this following error-
com.microsoft.sqlserver.jdbc.SQLServerException: This driver is not
configured for integrated authentication
But if i stop the server before changing any file and start after changing and run the project then it works without any error.
Stopping and re-starting the server again and again taking so many times from my total project time! Any help or suggestion will be appreciated.
Thank You.
I solved my problem!
The error (described in my question above) i was getting because the glassfish server had not any access on sqljdbc42.jar file. so i have placed the sqljdbc42.jar file into my glassfish server in this location-
glassfish-4.1\glassfish\domains\domain1\lib.
And it's now working perfectly.
Thank you everyone!
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'm trying to load a NetBeans project that is not mine. When I do so, I get a data source resolution error, so I right-click on the project under the "Projects" view and try and create a new connection to the unresolved database, which returns a connection error once the connection is tested. How do I fix this issue? Is it a problem w/ some other component?
You have to set the Resource in the GlassFish, so it can connect the mysql, Just look at the following link---->Netbeans Help