Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.*;
- import java.io.PrintWriter;
- public class GetIt {
- public static void main(String args[]){
- // Load and register a JDBC driver
- try {
- // Load the driver (registers itself)
- Class.forName("com.mysql.jdbc.Driver");
- } catch (Exception E) {
- System.err.println("Unable to load driver.");
- E.printStackTrace();
- }
- try {
- // Connect to the database
- Connection conn1;
- String dbUrl = "jdbc:mysql://proj309-ds-02.misc.iastate.edu";
- String user = "user";
- String password = "userPassword6!";
- conn1 = DriverManager.getConnection(dbUrl, user, password);
- System.out.println("*** Connected to the database ***");
- // Create Statement and ResultSet variables to use throughout the
- // project
- Statement statement = conn1.createStatement();
- ResultSet rs;
- statement.executeUpdate("use roll19");
- rs = statement.executeQuery("select * from dudTest");
- rs.next();
- System.out.println(rs.getString("testInt"));
- } catch (SQLException e) {
- System.out.println("SQLException: " + e.getMessage());
- System.out.println("SQLState: " + e.getSQLState());
- System.out.println("VendorError: " + e.getErrorCode());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement