Sat Apr 14, 2012 3:21 am
Sat May 12, 2012 11:27 pm
import java.sql.*;
public Connection openConnection() {
Properties properties = new Properties();
properties.put("user", ...);
properties.put("password", ...);
properties.put("characterEncoding", "ISO-8859-1");
properties.put("useUnicode", "true");
String url = "jdbc:mysql://hostname/database";
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection c = DriverManager.getConnection(url, properties);
return c;
}
Connection c = createConnection();
Statement st = c.createStatement();
int id = 1; //Any value
String sql = "SELECT Name FROM students WHERE Id = " + id;
ResultSet rs = st.executeQuery(sql);
ResultSet rs = st.getResultSet();
try {
while (rs.next()) {
int id = rs.getInt(1);
String userName = rs.getString(2);
String firstName = rs.getString(3);
String surname = rs.getString(4);
Timestamp timeReg = rs.getTimestamp(5);
}
} finally {
rs.close();
}
http://netbeans.org/kb/docs/ide/java-db.html
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com
Powered by phpBB © phpBB Group.