Connecting to Mysql

From MyWiki
Revision as of 12:51, 19 October 2014 by George2 (Talk | contribs)

Jump to: navigation, search
import.java.sql.*;
 
{
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
String userName = "";
String passWord = "";
String sql = "";
String url = "jdbc:mysql://localhost<dbname>"
Class.forName("com.mysql.jdbc.Driver").newInstance();
con = DriverManager.getConnection(url,userName,passWorrd);
sql = "Put the sql query in here";
 
stmt = con.createStatement();
rs = stmt.executeQuery(sql);
 
while ( rs.next())
                  {
                 // Do stuff
                  }