Difference between revisions of "Connecting to Mysql"

From MyWiki
Jump to: navigation, search
Line 8: Line 8:
 
ResultSet rs = null;
 
ResultSet rs = null;
  
String userName = "";
+
String userName = "<username>";
String passWord = "";
+
String passWord = "<password>";
 
String sql = "";
 
String sql = "";
 
String url = "jdbc:mysql://localhost<dbname>";
 
String url = "jdbc:mysql://localhost<dbname>";

Revision as of 13:06, 19 October 2014

import java.sql.*;
 
{
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
 
String userName = "<username>";
String passWord = "<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
                  }