Difference between revisions of "Connecting to Mysql"
From MyWiki
Line 7: | Line 7: | ||
Statement stmt = null; | Statement stmt = null; | ||
ResultSet rs = null; | ResultSet rs = null; | ||
+ | |||
String userName = ""; | String userName = ""; | ||
String passWord = ""; | String passWord = ""; | ||
String sql = ""; | String sql = ""; | ||
− | String url = "jdbc:mysql://localhost<dbname>" | + | String url = "jdbc:mysql://localhost<dbname>"; |
+ | |||
Class.forName("com.mysql.jdbc.Driver").newInstance(); | Class.forName("com.mysql.jdbc.Driver").newInstance(); | ||
con = DriverManager.getConnection(url,userName,passWorrd); | con = DriverManager.getConnection(url,userName,passWorrd); |
Revision as of 12:52, 19 October 2014
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 }