Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.*;
- public class HelloWorld {
- public static void main(String[] args)
- {
- // TODO Auto-generated method stub
- System.out.println("Hello world!");
- System.out.println(System.getProperty("java.class.path"));
- Connection connection = null;
- Statement stmt = null;
- ResultSet rs = null;
- ResultSet rs2 = null;
- PreparedStatement query = null;
- try {
- System.out.println("Create the driver instance.<br>");
- Class.forName("com.mysql.jdbc.Driver").newInstance();
- System.out.println("Get the connection.<br>");
- connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/philstestschema", "root", "root1234");
- // query = connection.prepareStatement( "SELECT * FROM philstable");
- stmt = connection.createStatement();
- rs = stmt.executeQuery("SELECT username, firstname, surname FROM philstable");
- System.out.println("Made it past the query");
- while (rs.next())
- {
- String username = rs.getString("username");
- String firstname = rs.getString("FIRSTNAME");
- String surname = rs.getString("SURNAME");
- System.out.println(username + "\t" + firstname + "\t" + surname);
- }
- } catch (Exception e)
- {
- System.out.println("Phils Exception Handler");
- System.out.println(e.toString()+"<br>");
- }
- finally {
- // it is a good idea to release
- // resources in a finally{} block
- // in reverse-order of their creation
- // if they are no-longer needed
- if (rs != null) {
- try {
- rs.close();
- } catch (SQLException sqlEx) { } // ignore
- rs = null;
- }
- if (stmt != null) {
- try {
- stmt.close();
- } catch (SQLException sqlEx) { } // ignore
- stmt = null;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement