import java.sql.*;
import java.io.*;
class studtable
{
public
static void main(String ar[]) throws SQLException,
ClassNotFoundException,IOException
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection
con =
DriverManager.getConnection("jdbc:odbc:dbaccess","my","asa");
System.out.println("Connection
Established...");
BufferedReader
br = new BufferedReader(new InputStreamReader(System.in));
System.out.print("\nEnter
Roll No: ");
int
no = Integer.parseInt(br.readLine());
System.out.print("\nEnter
Subject Name: ");
String
name = br.readLine();
System.out.print("\nEnter
Percentage: ");
int
per = Integer.parseInt(br.readLine());
PreparedStatement
pstmt = con.prepareStatement("Insert into student values(?,?,?)");
pstmt.setInt(1,no);
pstmt.setString(2,name);
pstmt.setInt(3,per);
System.out.println("Record Added");
int i =
pstmt.executeUpdate();
Statement
stmt = con.createStatement();
ResultSet
rs = stmt.executeQuery("Select * from student");
while(rs.next())
System.out.println("Roll No: "+ rs.getString(1) + " Subject Name: "+ rs.getString(2) +
" Percentage: " +
rs.getString(3));
}
}
Post a Comment