-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjdbc.java
More file actions
31 lines (27 loc) · 953 Bytes
/
jdbc.java
File metadata and controls
31 lines (27 loc) · 953 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
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
//compile --> javac -cp "lib/*" jdbc.java
//run --> java -cp "lib/*;." jdbc
public class jdbc {
public static void main(String[] args) {
// String url="jdbc:oracle:thin:@localhost:8080:xe";
String url="jdbc:mysql://localhost:3308/rds";
String uname="root";
String pass="1234";
try{
// Class.forName("oracle.jdbc.driver.OracleDriver");
Class.forName("com.mysql.cj.jdbc.Driver");
Connection conn = DriverManager.getConnection(url,uname,pass);
Statement st = conn.createStatement();
ResultSet rs=st.executeQuery("select * from student");
while(rs.next()){
System.out.println(rs.getString(2));
}
}
catch(Exception e){
System.out.println("Error: "+e);
}
}
}