Hey there,
I finally took the plunge into Java and I have no clue how to query mysql from an applet. Anyone out there know what I need to do?? Thanks for any help you can give me.
Jade
Java and mysql??
Moderator: General Moderators
- scorphus
- Forum Regular
- Posts: 589
- Joined: Fri May 09, 2003 11:53 pm
- Location: Belo Horizonte, Brazil
- Contact:
You must download the MySQL JDBC Driver. It can be downloaded here[MySQL Connector/J 3.0]. Open the instructions file (README) and follow the installation steps.
Then go to the JDBC API Documentation and follow the JDBC Basics lesson.
I took a couple hours to install things and perform various tests. One of them (pretty simple):
Hope it helps. Regards,
Scorphus.
Then go to the JDBC API Documentation and follow the JDBC Basics lesson.
I took a couple hours to install things and perform various tests. One of them (pretty simple):
Code: Select all
import java.sql.*;
/**
*
* @author Scorphus
*/
public class JDBCTest {
/** Creates a new instance of JDBCTest */
public JDBCTest() {
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/bonsuc?user=bonsuc&password=bonsuc");
Statement stmt = conn.createStatement();
String query = "show tables";
ResultSet rs = stmt.executeQuery(query);
while (rs.next()) {
String s = rs.getString(1);
System.out.println(s);
}
rs.close();
}
catch (Exception e) {
System.out.println("Error: " + e);
}
return;
}
public static void main (Stringї] args) {
JDBCTest test = new JDBCTest();
return;
}
}Scorphus.