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. Can you provide some more specific application of
View Tutorial          By: Rushikesh at 2012-01-15 18:23:36

2. Is there any way to show the dynamic bean value in
View Tutorial          By: Bala at 2008-05-04 01:40:18

3. I am getting

jayana-desktop/127.0.

View Tutorial          By: GSA at 2010-11-23 02:36:26

4. awesome. thanks for the info
View Tutorial          By: Darren at 2010-05-09 19:55:22

5. me too
View Tutorial          By: bellyjoy at 2010-05-07 03:14:14

6. Thanks a lot. It was very helpful
View Tutorial          By: Faith Justin at 2008-12-07 06:52:29

7. For Jaime,

Maybe using JavaScript f

View Tutorial          By: Jair Aviles at 2011-11-22 05:49:05

8. is good bot not full
View Tutorial          By: amin parishani iran at 2010-07-07 10:51:33

9. Hi Prathamesh,
Maybe the COM port to which

View Tutorial          By: Ramlak at 2007-03-19 00:46:49

10. how to display image on gridview from mysql databa
View Tutorial          By: chirag at 2013-03-18 08:12:46