-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSqlDemo.java
More file actions
33 lines (28 loc) · 1007 Bytes
/
SqlDemo.java
File metadata and controls
33 lines (28 loc) · 1007 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
32
33
package jdbc;
import java.sql.*;
public class SqlDemo {
public static void main(String[] args) throws ClassNotFoundException, SQLException {
String url ="jdbc:mysql://localhost:3306/Java30Jan";
String username="root";
String password="Codekul@123";
Class.forName("com.mysql.cj.jdbc.Driver");
Connection con =DriverManager.getConnection(url,username,password);
Statement st = con.createStatement();
ResultSet resultSet = st.executeQuery("select * from student");
while (resultSet.next()){
System.out.println("---------Student---------------");
System.out.println("Roll No "+resultSet.getInt(1));
System.out.println("Name No "+resultSet.getString(2));
System.out.println("Age "+resultSet.getInt(3));
}
con.close();
}
}
//class Demo{
// {
// System.out.println("in instance block");
// }
// static {
// System.out.println("in static block");
// }
//}