How to connect NetBeans to MySQL database? - java

I have just installed NetBeans 7.0 and I am a newbie in NetBeans' world. can any one tell me how to connect my application to MySQl / Postgres ? I work on Windows XP.

In the Services window you can right click on the Databases tab and select New Connection.
Select MySQL(Connector/J Driver) from the drop down list. The driver file should be listed in the window. If not, you can download the file, then click add and select it from your hard drive.
Finally enter your database details such as servername, username and password and click finish.

One way to connect to such databases is to use a JDBC (Java Database Connectivity) driver. You can find more about JDBC at the Oracle FAQ.

If you meant you want to use IDE's GUI tool then
windows > services >database > driver
Get the driver jar
install the jar
right click on driver installed > connect using > and then provide the information
Or otherwise use JDBC

click on window and then select services
then click on databases and select new connection
select driver which you want
then click finish
if you want to check the connection is successful or not
try
{
con=DriverManager.getConnection("jdbc:mysql://localhost/student_result","root","");
JOptionPane.showMessageDialog(null,"connected with "+con.toString());
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null,"not connect to server and message is"+e.getMessage());
}

see mysql .jar for u project properties if u waant to run or for netbeans shown by #Vincent Ramdhanie

Follow the steps:-
1.Create a new application
2.In projects section of netbeans right click on libraries
3.Check the picture(i)Libraries java mysql connector
Thus you successfully setup the connection with mysql.

Related

Domino Designer can't "TeamDevelopment > Sync with On-Disk Project"

I am Using the Domino Designer 9.0, FP 8 and I can't sync my Gitrepositry with my Java Code on my Database.
Sometimes it works just fine, but most of the time the Designer shows me the Sync Conflict window. For my files I always select Use "On-Disk Project Version". The Window closes and opens up again.
When I open a file which should have changed,edit and save it, the "Sync Conflict" window opens up again. So i assume the designer knows the different files but can't write into my database(?).
What I have tried to fix to problem so far:
-Deleting local replica and create a new local replica
-Remove database from Designer and reassociate the git with the database
-changing the properties of the Java files (Prohibit reffresh or replace to modify)
-rebuild, refresh etc.
You can try Swiper from OpenNTF link
After install plug-in use toolbar buttons, it's work for me.

After Installing NetBeans 8.0.2 with GlassFish 4.1 Cannot Connect to sample Database

I installed NetBeans 8.0.2 with glassfish-4.1. The sample folder is present under C:\Users\Username.netbeans-derby. When I bring up NetBeans and go to the Services tab the connection to sample is present: jdbc:derby://localhost:1527/sample [app on APP] but sample is not listed under Java DB so when I try to connect to sample I get the following error "Unable to connect. Cannot establish a connection to jdbc:derby://localhost1527/sample using org.apache.derby.jdbc.ClientDriver (The connection was refused becuase the database sample was not found)."
Right click on Java DB select Create Database.
use as Database Name 'sample'
use as User Name 'app'
leave the password empty
edit
Seems there is a broken database or maybe one from an earlier Netbeans installation. Remove the sample connection in Netbeans and remove the directory %USERPROFILE%\.netbeans-derby\sample. Recreate the sample database as described above.
I had a broken database from an earlier version too, and then couldn't connect to the sample db.
I simply had to delete the .netbeans-derby directory,
then reinstalled Netbeans,
and is was ok, then.
The same thing happened to me and re-installing NetBeans did not help. After poking around the databases for a bit, I finally got mine working using the following process.
Create a new database with any properties (i.e. name, user, pw)
Navigate to your user directory \.netbeans-derby\{name}\
Copy service.properties file and paste in \.netbeans-derby\sample\
Reconnect to sample database in NetBeans
A couple extra notes:
If you configured your NetBeans database to a different location, use that location in step 2.
You may need to delete and re-create the existing sample database connection in NetBeans for it to pickup the new service.properties file.

Embed Derby DB with Netbeans Platform Application - Module

I developed a project in Netbeans Platform Application i.e. like Modules.
When i run my project from Netbeans 7.4, it works fine and doesn't show any DB exception.
Now i created a installer using Netbeans 7.4 for my project. wen i install it, the DB is also installed but its not recognizing the DB and my connection url is public final static String connectionURL = "jdbc:derby:ProjectDB;create=true;user=user;password=p#ssword";.
When i copy paste the DB alone in a location eg: " d:\project DB " and change the code as connectionURL = "jdbc:derby:D:\\project DB; create=true; user=user; password=p#ss" it works fine. But i need to create along with the installer or want my project to recognize the DB.
When i searched i got the below links
https://platform.netbeans.org/tutorials/70/nbm-crud.html
https://platform.netbeans.org/tutorials/nbm-crud.html
but dint get a solution.
Hard to tell from your description, but could you be seeing this default schema with Netbeans issue ?
Found the Solution..
launh or run the project after doing clean Build from the "dist" folder.
The new Database will be created in the "dist/project name" and you will get a error "Schema DB doesnt exists".
Now close the application and delete the DB in the "dist/project name" folder and copy-paste the DB(this i did for Derby Database) which you use for your project. And run the application agaiin.

Connect to a MySQL DB with JSP through another class

Can I connect to a MySQL DB with JSP through another class?
Here is my my own suggestion:
...<body>
<h3>The User List</h3>
<br>
<%
// JSP/Java kode
UsersDAPInterface users = new UserDAPClass(); // This java class contains mysql connection etc.
%>
</body>...
When I do this, I get a lot of errors and exceptions, including ClassNotFound, NullPointer etc.
I also got this:
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
Which should mean that it doesn't have the mysql driver.. But I have imported the mysql driver so I don't know if it should be imported in a different way than usually.
Any suggestions?
Make sure that this jar file in present in WEB-INF/lib folder of your application, as long as its present there, this issue should not come.
<jsp:useBean/> use this action to load any class to jsp. This is best practice.
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
This exceptions occurs due to your MySQL Connector Driver is not laoded. Use an IDE to load the driver. Manually check whether the com.mysql.jdbc.Driver is founded by writing it on Java class.
Download lib file from here and put it in your lib folder of your application. Have no idea what IDE are you using, but on Netbeans, take following steps:
Right click on your project
Select properties
In the category panel, select Libraries
Add jar folder just downloaded from Maven
You are ready.
You need to add jdbc driver class in your webapp library.

Netbean6.9 --- is there xml to define for database connection?

Goal:
Create Netbean project and put on repository (any). When other developers check out the Netbean project, they can "open project" from Netbean IDE and press execute to open browser and start testing web application.
I wrote REST web app (Toplink-essential, JAX-RS, SQL Server 2008) and this is the Netbean project other people want to open in Netbean IDE.
It's working actually except that when someone "open project" in Netbean, she still has to go to Data Source tab (next to Project and File tab), then manually create database connection by filling in the popup form (i.e typing host, db name, pick driver etc).
I found out under nbproject/setup/sun-resource.xml db drivers and name/password are defined but we had to do the first step (which is filling the popup form described earlier)
Is there way to eliminate the step? That means I can somewhere define in xml ???
Please let me know if you need more clarification.
i would comment on your post, but no such option for me atm, so have to post an answer.
What database conenction are you using ?
And try to implement a properties file rather than xml file !! and then its pretty straight forward, something like this:
MySQL
hibernate.dialect = org.hibernate.dialect.MySQLInnoDBDialect
hibernate.connection.driver_class =
com.mysql.jdbc.Driver
hibernate.connection.url =
jdbc:mysql://localhost/ - . . . -
hibernate.connection.username = root
hibernate.connection.password =
this might help
http://netbeans.org/kb/docs/java/project-setup.html#ide-concepts

Categories