Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package jdbcsqlex1;
- import java.sql.*;
- /**
- *
- * @author franciscocarvalho
- */
- public class JdbcSQLex1 {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) throws SQLException, ClassNotFoundException {
- // TODO code application logic here
- Class.forName("com.mysql.jdbc.Driver");
- //---- define connection
- Connection connect = DriverManager.getConnection("jdbc:mysql://localhost:3306/java","root","");
- //----- define statement
- Statement stat = connect.createStatement();
- //----- define query
- ResultSet rset = stat.executeQuery("select * from books");
- //----- visualize data
- while (rset.next()){
- System.out.println(rset.getString(1) + "\t" + rset.getString(2) + "\n" + rset.getString(3));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement