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) {
- Connection con = null;
- try {
- Class.forName("com.mysql.jdbc.Driver").newInstance();
- con = DriverManager.getConnection("jdbc:mysql:///carlsdb", "root", "14142135");
- if(!con.isClosed()) {
- System.out.println("Successfully connected to MySQL server...");
- Statement stmt = con.createStatement();
- ResultSet rs = stmt.executeQuery("SELECT * FROM testtable;");
- rs.next();
- System.out.println(rs.getString("name"));
- }
- } catch(Exception e) {
- System.err.println("Exception: " + e.getMessage());
- } finally {
- try {
- if(con != null)
- con.close();
- } catch(SQLException e) {}
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement