forked from jvm-coder/Java_Programs
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathjava_database_connectivity.java
More file actions
49 lines (41 loc) · 1.19 KB
/
java_database_connectivity.java
File metadata and controls
49 lines (41 loc) · 1.19 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
45
46
47
48
49
package testdatabase;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
class TestDatabase28
{
public static void main(String args[])
{
Connection con = null;
Statement st = null;
ResultSet rs = null;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("Driver Loaded");
con = DriverManager.getConnection("jdbc:odbc:db28");
System.out.println("Connected");
st = con.createStatement();
String query = "Select * from emp";
rs = st.executeQuery(query);
while (rs.next())
{
System.out.print(rs.getString(1) + "\t");
System.out.print(rs.getString(2) + "\t");
System.out.print(rs.getString(3) + "\t");
System.out.println(rs.getString(4));
}
con.close();
}
catch (ClassNotFoundException e)
{
System.out.println(e);
}
catch (SQLException e)
{
System.out.println(e);
}
}
}