-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathJdbcConnection.java
More file actions
50 lines (46 loc) · 1.53 KB
/
JdbcConnection.java
File metadata and controls
50 lines (46 loc) · 1.53 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
50
import java.sql.*;
//import javax.sql.*;
import java.util.*;
import java.io.*;
public class JdbcConnection
{
JdbcConnection()
{
}
public Connection conn() throws SQLException//method of class JdbcConnection
{
Connection conn;
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");//Load DB-specific JDBC driver
}
catch(ClassNotFoundException e)
{
System.out.println("Database Driver not found");
System.out.println(e.toString());
}
catch(Exception e)
{
System.out.println(e.toString());
}
//return(DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:XE","SYSTEM","Oracle1"));////Get a Connection object
return(DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:XE","monish001","oracle"));////Get a Connection object
}
public static void main(String args[]) throws SQLException,IOException
{
JdbcConnection c=new JdbcConnection();
//String qry= new String();
Connection con=c.conn();//Get a Connection object
Scanner in=new Scanner(System.in);
Statement stmt = con.createStatement();//Get a Statement object
ResultSet rset; // = stmt.executeQuery("select max(studentid) from student");
String qry=new String("select * from batch");//Execute queries and/or updates
rset=stmt.executeQuery(qry);
//System.out.println("Name\tNull?\tType");
while(rset.next())
{
System.out.println(rset.getString(1));
}
//close(con);
}
}