Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- public class Main {
- public static void main(String[] args) throws Exception {
- //Accessing driver from the JAR file
- Class.forName("com.mysql.jdbc.Driver");
- //Creating a variable for the connection called "con"
- Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/jedi","root", "qwert");
- //jdbc:mysql://localhost:3306/employee_record --> this is the database
- //root is the database user
- //qwerty is the password
- //Here we create our query
- PreparedStatement statement = con.prepareStatement("select image from page");
- //Creating a variable to execute query
- ResultSet result = statement.executeQuery();
- while(result.next()) {
- System.out.println(result.getString(1));
- //getString returns the data
- //1 is the first field in the table
- //2 is teh second field
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement