forked from vabburi82/Java8Examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDbRetriveOperation.java
More file actions
31 lines (26 loc) · 823 Bytes
/
Copy pathDbRetriveOperation.java
File metadata and controls
31 lines (26 loc) · 823 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package com.sample;
import java.sql.*;
public class DbRetriveOperation {
public static void main(String[] args) throws SQLException {
// TODO Auto-generated method stub
Connection con = null;
try{
Class.forName("com.mysql.jdbc.Driver");
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/mydatabase","root","root");
System.out.println("Connected Successfully........!");
}
catch(Exception e)
{
System.out.println(e);
}
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("select * from user_data;");
while(rs.next()) {
System.out.print("Name:"+rs.getString(1)+"\t");
System.out.print("Eamil:"+rs.getString(2)+"\t");
System.out.print("Phone:"+rs.getInt(3)+"\t");
System.out.println(" ");
}
con.close();
}
}