-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBasicSteps.java
More file actions
52 lines (32 loc) · 1.06 KB
/
BasicSteps.java
File metadata and controls
52 lines (32 loc) · 1.06 KB
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
34
35
36
37
38
39
40
41
42
43
44
package jdbc;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
/*
* 1) import the packages. (java.sql.*;) --> Connector
* 2) Load & Register the Drivers. --------->
* 3) Establish the Connection. ------------>
* 4) Create the Statement. ---------------->
* 5) Execute the Query. ------------------->
* 6) Process the Result. ------------------>
* 7) Close. ------------------------------->
*
*/
public class BasicSteps {
public static void main(String[] args) throws Exception {
String url = "jdbc:mysql://localhost:3306/school";
String uname = "root";
String passwd = "root123";
String query = "select sname from student where rollno = 41";
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection(url, uname, passwd);
Statement st = con.createStatement();
ResultSet rs = st.executeQuery(query);
rs.next();
String name = rs.getString("sname");
System.out.println(name);
st.close();
con.close();
}
}