Comment on Tutorial - Using JDBC to connect to MySQL from Java Program By Rajan
Comment Added by : Anand
Comment Added at : 2012-11-12 00:00:07
Comment on Tutorial : Using JDBC to connect to MySQL from Java Program By Rajan
package com.anand;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class MySqlProjMain {
MySqlProjMain () {
init();
}
private void init() {
String dbUrl = "jdbc:mysql://localhost:3306/world";
String dbDriverClass = "com.mysql.jdbc.Driver";
String sql = "Select * from country";
String userName = "root", password = "password";
try {
Class.forName(dbDriverClass);
Connection conn = DriverManager.getConnection(dbUrl, userName, password);
Statement st = conn.createStatement();
ResultSet rs = st.executeQuery(sql);
while (rs.next()) {
System.out.println( rs.getString("name") );
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
MySqlProjMain main = new MySqlProjMain();
System.out.println("hello world");
}
}
View Tutorial
- Data Science
- Android
- AJAX
- ASP.net
- C
- C++
- C#
- Cocoa
- Cloud Computing
- HTML5
- Java
- Javascript
- JSF
- JSP
- J2ME
- Java Beans
- EJB
- JDBC
- Linux
- Mac OS X
- iPhone
- MySQL
- Office 365
- Perl
- PHP
- Python
- Ruby
- VB.net
- Hibernate
- Struts
- SAP
- Trends
- Tech Reviews
- WebServices
- XML
- Certification
- Interview
categories
Subscribe to Tutorials
Related Tutorials
Program using concept of byte long short and int in java
Update contents of a file within a jar file
Tomcat and httpd configured in port 8080 and 80
Count number of vowels, consonants and digits in a String in Java
Student marks calculation program in Java
Calculate gross salary in Java
Calculate average sale of the week in Java
Vector in Java - Sample Program
MultiLevel Inheritance sample in Java
Archived Comments
1. sir can you write the sample proram of this:
View Tutorial By: bryan labastida at 2011-06-29 02:53:14
2. Very easy and simple to understand....good article
View Tutorial By: Ashish at 2009-10-07 00:58:08
3. FileOutputStream will create the file if it does n
View Tutorial By: Peter at 2012-02-07 13:25:16
4. pls give me example of stack class with postfix me
View Tutorial By: uchiha at 2011-09-16 04:02:57
5. This is just the web service, if you want to consu
View Tutorial By: Carlos Kassab at 2015-02-20 17:18:06
6. Comment: yes i understood too:D:D perfect and brei
View Tutorial By: eman at 2009-04-21 23:57:26
7. Hi,
I wann to insert data into excel file b
View Tutorial By: PRUTHVIRAJ RATHOD at 2011-05-23 11:42:14
8. great, thnak you very much !!!!
View Tutorial By: geek at 2014-05-11 00:10:32
9. Well written article! Thank You ! My maven build i
View Tutorial By: Nagesh at 2014-11-20 07:44:00
10. Very good explanation but i need to know how the c
View Tutorial By: surender at 2011-11-17 11:15:22