Use MySQL JDBC Connector

Download JDBC connector. Include the library in the class-path.

Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://" + host + "/" + db, user, password);

Statement s = conn.createStatement();
String sql = "SELECT * FROM person";
s.execute(sql);
ResultSet rs = s.getResultSet();
while(rs.next()){
	System.out.println(rs.getString("name") + "\t" + rs.getInt("age") + "\t" + rs.getString("sex") + "\t" + rs.getString("location"));
}
rs.close();
s.close();
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: