Difference between revisions of "Connecting to Mysql"
From MyWiki
Line 1: | Line 1: | ||
<source lang="java"> | <source lang="java"> | ||
− | import | + | import java.sql.*; |
{ | { |
Revision as of 13:00, 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 }