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

Java program to get location meta data from an image

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

Archived Comments

1. can anyone explain the output of this recursive ex
View Tutorial          By: vipul at 2012-08-12 19:41:19

2. Thx for the explanation, I understand what recursi
View Tutorial          By: Tina at 2008-12-15 16:39:27

3. pls give us aprogram of postfix and infix using st
View Tutorial          By: lost_hope1111 at 2009-02-13 01:48:37

4. thanks to this site which get me understand about
View Tutorial          By: Sayak at 2012-10-08 15:57:25

5. thanks for our help. god bless u and again thanks.
View Tutorial          By: mehryab at 2011-05-08 14:44:21

6. worked for me thanks.
View Tutorial          By: dem125 at 2010-08-03 23:30:32

7. This is the best example for beginners. After read
View Tutorial          By: BB at 2014-05-20 05:24:09

8. Hi Sir...
sir i am working on Speech to Tex

View Tutorial          By: Sadaquat at 2012-08-19 07:51:28

9. this code is not working properly buddies. please
View Tutorial          By: hammad at 2011-06-10 01:53:39

10. this is WRONG!

your IF should be:
View Tutorial          By: notnooblikeyou at 2013-01-29 15:11:30