Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.*;
- import java.util.Properties;
- public class DBDemo {
- // The JDBC Connector Class.
- private static final String dbClassName = "com.mysql.jdbc.Driver";
- // Connection String. Emotherearth is the database the program is
- // connecting to. You can include user and password after this by adding
- // (say) ?user=paulr&passowrd=pualr. Not recomended!
- private static final String CONNECTION =
- "jdbc:mysql://127.0.0.1/emotherearth";
- public static void main(String[] cl_args) throws
- ClassNotFoundException, SQLException
- {
- System.out.println(dbClassName);
- // Class.forName(xxx) loads the jdbc classes and creates
- // a drivermanager class factory
- Class.forName(dbClassName);
- // Properties for user and password. Here the user and password are xellophane and 'Gr3yh@t'
- Properties p = new Properties();
- p.put("user", "xellophane");
- p.put("password", "Gr3yh@t");
- // Now try to connect
- Connection c = DriverManager.getConnection(CONNECTION, p);
- System.out.println("It works! ");
- c.close();
- }
- }
Add Comment
Please, Sign In to add comment