Overview : mariadb 연결하기
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.Iterator; public class TestJDBC { public static void main(String[] args) { try { Class.forName("org.mariadb.jdbc.Driver"); Connection con = DriverManager.getConnection("jdbc:mariadb://localhost:3306/Demo?user=admin&password=admin"); Statement stmt = con.createStatement(); ResultSet rs = stmt.executeQuery("select * from login"); rs.beforeFirst(); System.out.println("printing database info...."); while(rs.next()) { System.out.println(rs.getString(1)+" "+rs.getString(2)); } }catch (ClassNotFoundException e) { System.out.println(e.getMessage()); }catch(SQLException e) { System.out.println(e.getMessage()); } } } |