![]() Regarding your setup, the main things you’ll need are a Java compiler (SDK), the MySQL JDBC database driver, and a MySQL instance running on your computer (or running on another computer you can access). Of course your output will vary depending on the actual data in your database table. ("Got an exception! ") Īssuming that everything is set up properly on your computer system, you should see output like this when you run this example Java program: ("%s, %s, %s, %s, %s, %s\n", id, firstName, lastName, dateCreated, isAdmin, numPoints) String lastName = rs.getString("last_name") ĭate dateCreated = rs.getDate("date_created") īoolean isAdmin = rs.getBoolean("is_admin") String firstName = rs.getString("first_name") execute the query, and get a java resultset if you only need a few columns, specify them by name instead of using "*" String myUrl = "jdbc:mysql://localhost/test" Ĭonnection conn = DriverManager.getConnection(myUrl, "root", "") * MySQL database, called from a Java program. * Demonstrates the use of a SQL SELECT statement against a Note that in this example my MySQL database username is “root”, my password is blank, and the database is running on the same computer where this program is run, so the database host name is “localhost”: I tried to document the following Java/MySQL SELECT example so you can see these steps.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |