-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDemo1.java
More file actions
38 lines (33 loc) · 1.24 KB
/
Demo1.java
File metadata and controls
38 lines (33 loc) · 1.24 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
//SET PATH=F:\SOFT\JDK 7\bin
import java.sql.*;
public class Demo1 {
public static void main(String[] args) {
try{
// Load and register the driver
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(Exception e) {
e.printStackTrace();
}
//Driver myDriver = new sun.jdbc.odbc.JdbcOdbcDriver();
//DriverManager.registerDriver(myDriver);
// Establish the connection to the database server
// urlstring,enter workspace username or SYSTEM,password
Connection cn = DriverManager.getConnection("jdbc:odbc:CollegeekDSN","admin","admin");
// Create a statement
Statement st = cn.createStatement();
// Execute the statement
ResultSet rs = st.executeQuery("select * from Student");
// Retrieve the results
while(rs.next())
System.out.println(rs.getString(1)+" "+rs.getString(2));
// Close the statement and connection
st.close();
cn.close();
}
catch(SQLException e) {
System.out.println(e.getMessage());
}
}
}