How is a MySQL database properly connected to in NetBeans? - java

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

Related

Unable to make connection between mysql 8.0.18 with eclipse 2019-09

I have mysql8.0.18 installed on machine and eclipse 2019-09 but unable to make connection between them, It run the first page but unable to make connection with database.
HTTP Status 500 – Internal Server Error
maybe this post can help you man post link
. To use mysql in eclipse, you should import connector: mysql-connector-java-5.1.45-bin.jar or some later version in the Eclipse web-inf lib.
Moreover, you should make your question clearer such as what kind of project u are working on, ... that much helps us to help in more detail

Netbeans persistence.xml - definition of path for persistence unit

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?

No suitable driver found for jdbc:db2 with db2jcc4.jar present in web-inf\lib

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?

sqljdbc4 2 on Glassfish server4 1

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!

Error while connecting to Oracle DSN using Java

I need to develop an application that connects to various DSN's using the Microsoft ODBC drivers. I have developed the application in Eclipse and it seems to work properly. The connection succeeds and I am able to view table data.
However when I export the project to a runnable jar file (using Eclipse) the functionality fails for Oracle. It is unable to establish connectivity with the Oracle connection string. It still works for SQL server but fails in case of Oracle. I'm unable to figure out the cause as the same ODBC drivers are being used for both Oracle and SQL-Server. More mystifying is that it runs properly on Eclipse. Since im using the ODBC drivers I don't believe the problem is because of an external jar file.
The driver is sun.jdbc.odbc.JdbcOdbcDriver and connection string is like jdbc:odbc:oratest;user=fell;password=pass.
I'm getting the following exception
java.sql.SQLException: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6958)
Can you please help me figure what the problem might be?
Thanks in advance,
Fell
Create a System DSN.
java.sql.Connection cn;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
cn=java.sql.DriverManager.getConnection("jdbc:odbc:dsn_name","user","pass");
Check the classpath in the eclipse project

Categories

Resources