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



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

Java File

Java String

Count number of vowels, consonants and digits in a String in Java

Reverse a number in Java

Student marks calculation program in Java

Handling Fractions 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

Multiple Inheritance sample in Java

Java program using Method Overriding

Archived Comments

1. Very usefull tutorial, but I've got a question:
View Tutorial          By: Wolfgang Marcos at 2011-05-16 11:12:19

2. tell me the new page create in java and attach wi
View Tutorial          By: muhammad nadeem at 2011-07-06 00:12:08

3. Hi,
I'm studying core java.java is new for

View Tutorial          By: shantkumar at 2011-12-01 17:02:26

4. can any beginners can try creating web pages

View Tutorial          By: jo at 2015-07-28 19:35:11

5. thank's
View Tutorial          By: gerald at 2010-08-06 01:21:39

6. Your answer was right on the money! After searchi
View Tutorial          By: ooh la la at 2013-07-19 20:33:41

7. Thank you very much for this tip.
View Tutorial          By: Lise at 2011-07-15 13:27:23

8. Easy to understand.......
View Tutorial          By: Priya at 2013-02-15 10:55:52

9. Its very clearly explained.
View Tutorial          By: sowjanya at 2013-10-04 09:26:04

10. It too good code
View Tutorial          By: Srinivas at 2011-02-20 03:58:19