Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package sql;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- import com.mysql.jdbc.Statement;
- public class Main {
- public static void main(String[] args) throws ClassNotFoundException, SQLException {
- Class.forName("com.mysql.jdbc.Driver");
- java.sql.Connection conn1 = null;
- try {
- // connect way #1
- String url1 = "jdbc:mysql://sql2.freemysqlhosting.net:3306/sql2215281";
- String user = "sql2215281";
- String password = "dZ8%xB2!";
- conn1 = DriverManager.getConnection(url1, user, password);
- if (conn1 != null) {
- System.out.println("Connected to the database");
- }
- } catch (SQLException ex) {
- // handle any errors
- System.out.println("SQLException: " + ex.getMessage());
- System.out.println("SQLState: " + ex.getSQLState());
- System.out.println("VendorError: " + ex.getErrorCode());
- }
- java.sql.Statement statement = conn1.createStatement();
- statement.execute("sql statement here")
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement