JAVA   50

mysql

Guest on 11th May 2022 04:42:43 PM

  1. import java.sql.*;
  2.  
  3. final class SQL {
  4.     final static String user = "root";
  5.     final static String password = "root";
  6.     final static String db = "database";
  7.     final static String jdbc = "jdbc:mysql://localhost:3306/"+db+"?user="+user+"&password="+password;
  8.  
  9.     public static void main ( String[] args ) throws Exception {
  10.         Class.forName("com.mysql.jdbc.Driver").newInstance();
  11.         Connection con = DriverManager.getConnection(jdbc);
  12.         Statement stmt = con.createStatement();
  13.         ResultSet rs = stmt.executeQuery("select * from employee");
  14.         while (rs.next())
  15.             System.out.println(rs.getString("fname")+" "+rs.getString("lname"));
  16.         rs.close();
  17.         stmt.close();
  18.         con.close();
  19.     }
  20. }

Raw Paste


Login or Register to edit or fork this paste. It's free.