Skip to content

Commit ae90ff0

Browse files
authored
Create java_database_connectivity.java
1 parent bd1743c commit ae90ff0

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

java_database_connectivity.java

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package testdatabase;
2+
3+
import java.sql.Connection;
4+
import java.sql.DriverManager;
5+
import java.sql.ResultSet;
6+
import java.sql.SQLException;
7+
import java.sql.Statement;
8+
9+
class TestDatabase28
10+
{
11+
public static void main(String args[])
12+
{
13+
Connection con = null;
14+
Statement st = null;
15+
ResultSet rs = null;
16+
17+
try
18+
{
19+
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
20+
System.out.println("Driver Loaded");
21+
22+
con = DriverManager.getConnection("jdbc:odbc:db28");
23+
System.out.println("Connected");
24+
25+
st = con.createStatement();
26+
27+
String query = "Select * from emp";
28+
29+
rs = st.executeQuery(query);
30+
31+
while (rs.next())
32+
{
33+
System.out.print(rs.getString(1) + "\t");
34+
System.out.print(rs.getString(2) + "\t");
35+
System.out.print(rs.getString(3) + "\t");
36+
System.out.println(rs.getString(4));
37+
}
38+
con.close();
39+
}
40+
catch (ClassNotFoundException e)
41+
{
42+
System.out.println(e);
43+
}
44+
catch (SQLException e)
45+
{
46+
System.out.println(e);
47+
}
48+
}
49+
}

0 commit comments

Comments
 (0)