Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.*;
- class MysqlCon {
- public static void main(String args[]) {
- try {
- Class.forName("com.mysql.jdbc.Driver");
- Connection con = DriverManager.getConnection(
- "jdbc:mysql://localhost:3306/test_database", "root", "");
- Statement stmt = con.createStatement();
- ResultSet rs = stmt.executeQuery("select * from jdbc ");
- while (rs.next()) {
- System.out.println("Connected to Mysql Server successfully >>" + "\n\n" + rs.getInt(1) + " " + rs.getString(2) + " " + rs.getString(3) + " " + rs.getString(4) + " " + rs.getString(5) + " " + rs.getString(6) + " " + rs.getString(7) + " " + rs.getString(8) + "\n");
- }
- con.close();
- } catch (Exception e) {
- System.out.println(e);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement