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. Nice example for FileReader and FileWriter,

View Tutorial          By: Tim at 2009-10-21 17:31:00

2. ,Hi, (VS2008, VB.Net
I used the above code,

View Tutorial          By: Pat at 2012-06-27 17:30:37

3. in this statement "void Reverse(string &t
View Tutorial          By: vinay at 2012-12-13 16:41:59

4. Thanx.. it helps me a lot, now.. i have 1 more que
View Tutorial          By: GuzZpaWn at 2012-01-15 17:19:29

5. can anybody tell me the full code for sending sms
View Tutorial          By: shikha at 2008-10-13 11:43:40

6. hi every body i want full java code to send messag
View Tutorial          By: Yous at 2010-12-26 06:45:30

7. java program to maintain the books details like Bo
View Tutorial          By: Prabha at 2013-08-28 12:34:00

8. Hello sir pls send me
com.sun.speech.freett

View Tutorial          By: shanthi at 2013-03-22 11:18:56

9. hi i want to run a c program in java program but i
View Tutorial          By: jyothi at 2014-11-27 06:40:27

10. I have got "time out at step 6". How can
View Tutorial          By: MCHON at 2008-10-05 12:36:42