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



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. Can you mail me the compiled files, Please. Thank
View Tutorial          By: raghav at 2010-09-14 21:23:17

2. any body who have a full source code of the progra
View Tutorial          By: progra at 2013-02-11 12:37:34

3. What is the difference between:
CMUsphinx4-

View Tutorial          By: Netrika at 2011-11-26 19:55:07

4. I have download that 5 files .But how to run this
View Tutorial          By: Unnati at 2011-07-07 06:07:26

5. Hibernate with annotations and QBE api reduced our
View Tutorial          By: Andrew at 2011-04-29 10:34:26

6. very cool you said it! many thanks it's really coo
View Tutorial          By: ArAsh at 2008-12-11 06:41:13

7. it is very good website for IT students
View Tutorial          By: jeecee at 2013-03-21 12:23:46

8. hello, please i need a help.. i'm trying to make a
View Tutorial          By: Ludmila at 2012-12-10 17:56:00

9. What is the \ in several of the string building st
View Tutorial          By: rogerb at 2012-01-28 23:07:31

10. Thanks for your nice article.I learned a lot
View Tutorial          By: Mahyar at 2012-08-12 12:09:36