Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.*;
- public class JDBCTest {
- public static void main(String[] args) throws SQLException {
- Connection myConn = null;
- Statement myStmt = null;
- ResultSet myRs = null;
- try {
- myConn = DriverManager.getConnection("jdbc:mysql://localhost:3306/LibSys", "root", "");
- System.out.println("Database connection successful!\n");
- myStmt = myConn.createStatement();
- myRs = myStmt.executeQuery("select * from books");
- while (myRs.next()) {
- System.out.println(myRs.getString("book_name"));
- }
- }
- catch (Exception exc) {
- exc.printStackTrace();
- }
- finally {
- if (myRs != null) {
- myRs.close();
- }
- if (myStmt != null) {
- myStmt.close();
- }
- if (myConn != null) {
- myConn.close();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement