-
-
Save uncoded-ro/cb22467bd0943850eb914f557d0cf7ea to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ro.virtualcampus.db; | |
import java.sql.*; | |
public class Actors { | |
public static void main(String[] args) { | |
Connection conn = null; | |
Statement stmt = null; | |
ResultSet rs = null; | |
ResultSetMetaData meta = null; | |
try { | |
conn = DriverManager.getConnection("jdbc:mysql://data.virtualcampus.ro:3306/sakila", | |
"airman", "parola"); | |
stmt = conn.createStatement(); | |
rs = stmt.executeQuery("SELECT * FROM actor WHERE last_name LIKE 'B%' LIMIT 10;"); | |
meta = rs.getMetaData(); | |
for (int i = 0; i < meta.getColumnCount(); i++) | |
System.out.print(meta.getColumnName(i + 1) + "\t"); | |
System.out.print("\n"); | |
while (rs.next()) { | |
for (int i = 0; i < meta.getColumnCount(); i++) | |
System.out.print(rs.getObject(i + 1) + "\t"); | |
System.out.print("\n"); | |
} | |
} catch (SQLException e) { | |
System.out.println(e.getMessage()); | |
} catch (Exception e) { | |
System.out.println(e.getMessage()); | |
} finally { | |
try { | |
if (rs != null) | |
rs.close(); | |
if (stmt != null) | |
stmt.close(); | |
if (conn != null) | |
conn.close(); | |
} catch (SQLException e) { | |
System.out.println(e.getMessage()); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment