JDBC - Make a connection Java and MySQL

25comments



On this occasion I
will share about how to make a connection with MySQL Java. What we need here is NetBeans as the IDE, which would free version of what happened to me using NetBeans 7.0, but that we also need the XAMPP for MySQL database. Immediately, I explain codingnya below:

1. First we make a Java class in NetBeans with the name "Koneksi.java"
2. Then type in the script as below
:
-------------------------------------------------------------------------------
public class Koneksi {
Connection con;
String driver,url,user,pass;

public Koneksi() {
this.driver="com.mysql.jdbc.Driver";
this.url="jdbc:mysql://localhost:3306/kuliah";
this.user="root";
this.pass="root";
}

public Koneksi(Connection con, String driver, String url, String user, String pass) {
this.con = con;
this.driver = driver;
this.url = url;
this.user = user;
this.pass = pass;
}

public void BukaKoneksi(){
try {
Class.forName(driver).newInstance();
con = DriverManager.getConnection(url,user,pass);
} catch (SQLException ex) {
Logger.getLogger(Koneksi.class.getName()).log(Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
Logger.getLogger(Koneksi.class.getName()).log(Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
Logger.getLogger(Koneksi.class.getName()).log(Level.SEVERE, null, ex);
} catch (ClassNotFoundException ex) {
Logger.getLogger(Koneksi.class.getName()).log(Level.SEVERE, null, ex);
}
}

public Connection getCon() {
return con;
}

public void setCon(Connection con) {
this.con = con;
}
}
-------------------------------------------------------------------------------
Share this article :

+ comments + 25 comments

January 8, 2018 at 5:08 PM

Thank you for posting an excellent content, this is the best content I have never seen which is related to current technology. Refer me for IT studies and language courses.
Regards:
Big Data Hadoop Training in Chennai
Best hadoop training institute in chennai

June 27, 2018 at 6:23 PM

I have read your blog and i got a very useful and knowledgeable information from your blog. You have done a great job.

Java Training in Chennai | Java Training Institute in Chennai

September 5, 2018 at 6:46 PM

Your good knowledge and kindness in playing with all the pieces were very useful. I don’t know what I would have done if I had not encountered such a step like this.
Devops Training in Chennai

Devops Training in Bangalore

Devops Training in pune

September 10, 2018 at 6:23 PM

Very good brief and this post helped me alot. Say thank you I searching for your facts. Thanks for sharing with us!
python training institute in chennai
python training in Bangalore
python training in pune
python online training

September 18, 2018 at 1:25 PM

The post is written in very a good manner and it entails many useful information for me. I am happy to find your distinguished way of writing the post. Now you make it easy for me to understand and implement the concept.
Blueprism training in Pune

Blueprism online training

Blue Prism Training in Pune

September 24, 2018 at 1:31 PM

Thanks for splitting your comprehension with us. It’s really useful to me & I hope it helps the people who in need of this vital information. 
Data science training in tambaram | Data Science training in anna nagar
Data Science training in chennai | Data science training in Bangalore
Data Science training in marathahalli | Data Science training in btm

October 5, 2018 at 4:38 PM

The knowledge of technology you have been sharing thorough this post is very much helpful to develop new idea. here by i also want to share this.
java training in omr | oracle training in chennai

java training in annanagar | java training in chennai

November 3, 2018 at 1:24 PM

Do you mind if I quote a couple of your posts as long as I provide credit and sources back to your blog?
safety course in chennai

November 14, 2018 at 7:28 PM

Well Said, you have furnished the right information that will be useful to anyone at all time. Thanks for sharing your Ideas. block chain training in chennai | Selenium training in chennai

February 28, 2019 at 1:09 PM

This is really impressive post, I am inspired with your post, do post more blogs like this.
Devops Training in Chennai | Devops Training Institute in Chennai

March 3, 2019 at 1:44 PM

Amazing post.Thanks for your details and explanations..I want more information from your side.Thank you

Article submission sites
Guest posting sites

March 7, 2019 at 2:31 PM

Thanks for your informative article, Your post helped me to understand the future and career prospects & Keep on updating your blog with such awesome article.

Microsoft Azure online training
Selenium online training
Java online training
Java Script online training
Share Point online training


March 11, 2019 at 7:01 PM

I appreciate your efforts because it conveys the message of what you are trying to say. It's a great skill to make even the person who doesn't know about the subject could able to understand the subject . Your blogs are understandable and also elaborately described. I hope to read more and more interesting articles from your blog. All the best.
devops online training

aws online training

data science with python online training

data science online training

rpa online training

August 13, 2019 at 6:11 PM

It’s really a Great Post .Looking for Some More Stuff

salesforce Training in Bangalore
uipath Training in Bangalore
blueprism Training in Bangalore

August 19, 2019 at 6:49 PM

Thanks for the well-written post and I will follow your updates regularly and this is really helpful. Keep posting more like this.
salesforce Training in Bangalore
uipath Training in Bangalore
blueprism Training in Bangalore

November 26, 2019 at 4:33 PM

Thank you for your post. This is excellent information. It is amazing and wonderful to visit your site.

aws Training in Bangalore
python Training in Bangalore
hadoop Training in Bangalore
angular js Training in Bangalore
bigdata analytics Training in Bangalore

May 19, 2020 at 9:48 AM

Its an fantastic blog...

BEST ANGULAR JS TRAINING IN CHENNAI WITH PLACEMENT

https://www.acte.in/angular-js-training-in-chennai
https://www.acte.in/angular-js-training-in-annanagar
https://www.acte.in/angular-js-training-in-omr
https://www.acte.in/angular-js-training-in-porur
https://www.acte.in/angular-js-training-in-tambaram
https://www.acte.in/angular-js-training-in-velachery

August 15, 2020 at 12:16 AM

Awesome blog. I enjoyed reading your articles. This is truly a great read for me. oracle training in chennai

November 1, 2020 at 9:15 PM

It’s awesome that you want to share those tips with us. It is a very useful post Keep it up and thanks to the writer.
Angular js Training in Chennai

Angular js Training in Velachery

Angular js Training in Tambaram

Angular js Training in Porur

Angular js Training in Omr

Angular js Training in Annanagar

November 15, 2020 at 6:43 PM

Thanks for the well-written post and I will follow your updates regularly and this is really helpful. Keep posting more like this.
IELTS Coaching in chennai

German Classes in Chennai

GRE Coaching Classes in Chennai

TOEFL Coaching in Chennai

Spoken english classes in chennai | Communication training

January 10, 2022 at 7:29 PM

I really enjoy the article.Thanks Again. Fantastic.
best online java corse
java online classes

August 16, 2023 at 12:21 PM

very informative blog. very useful.
SQL course in Pune

Post a Comment

Ads

 
Support : Creating Website | Johny Template | Mas Template
Copyright © 2011. Share It Out - All Rights Reserved
Template Created by Creating Website Published by Mas Template
Proudly powered by Blogger