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. Not able to store on SD card.But storing on phone
View Tutorial          By: kusuma at 2015-07-25 13:42:17

2. I have tried that but still getting the same error
View Tutorial          By: pra at 2008-04-14 21:55:44

3. I am a B. Tech. (ECE) student, can i also give scj
View Tutorial          By: Sneha Agarwal at 2013-07-11 08:10:17

4. "For example, float can be useful when repres
View Tutorial          By: rangzen at 2014-03-28 09:31:47

5. thanks, i will try. but can u tell me how to send
View Tutorial          By: ketut joko wibawa at 2011-01-02 05:18:01

6. Excellent example! Thanks a ton:-)
One ques

View Tutorial          By: Andrew at 2009-04-11 09:15:19

7. could anyone run this program on Netbean? If there
View Tutorial          By: Wei Long at 2008-06-16 19:23:48

8. How to download a pdf file from the server and sav
View Tutorial          By: harsha at 2013-08-12 07:52:22

9. can any one plz tell me which java comm api do we
View Tutorial          By: GAURAV MODI at 2010-01-29 02:12:13

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