Difference between revisions of "Connecting to Mysql"
From MyWiki
| Line 13: | Line 13: | ||
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); | ||
| + | sql = "Put the sql query in here"; | ||
| + | |||
| + | stmt = con.createStatement(); | ||
| + | rs = stmt.executeQuery(sql); | ||
| + | |||
| + | while ( rs.next()) | ||
| + | { | ||
| + | // Do stuff | ||
| + | } | ||
| + | |||
</source> | </source> | ||
Revision as of 12:51, 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 }