0% found this document useful (0 votes)
744 views

Write A Program To Create A Student Table in Database and Insert A Record in Student Table

ajp practical 19
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
744 views

Write A Program To Create A Student Table in Database and Insert A Record in Student Table

ajp practical 19
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Write a program to Create A Student Table in Database And insert A Record in Student

table

package practical28;
/**
*
* @author vaish
*/
import java.sql.*;
import java.io.*;

class Practical28 {
public static void main(String[] args) {
DataInputStream dis = new DataInputStream(System.in);

try {
Connection con;
int empId;
String empName, empCity;

System.out.print("Enter Employee ID: ");


empId = Integer.parseInt(dis.readLine());

System.out.print("Enter Employee Name: ");


empName = dis.readLine();

System.out.print("Enter City: ");


empCity = dis.readLine();

String q = "INSERT INTO emp_info(empid, empname, empcity) VALUES(?, ?, ?)";


Class.forName("org.apache.derby.jdbc.ClientDriver");
con = DriverManager.getConnection("jdbc:derby://localhost:1527/sample");

PreparedStatement ps = con.prepareStatement(q);
ps.setInt(1, empId);
ps.setString(2, empName);
ps.setString(3, empCity);

ps.executeUpdate();

con.close();

System.out.println("Employee data inserted..");


} catch (Exception e) {
System.err.println(e.getMessage());
}
}
}

Output :

You might also like