-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJDBCex2.java
More file actions
31 lines (27 loc) · 878 Bytes
/
JDBCex2.java
File metadata and controls
31 lines (27 loc) · 878 Bytes
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
import java.sql.*;
import java.io.*;
public class JDBCex2
{
public static void main(String args[]) throws Exception
{
DataInputStream dis=new DataInputStream(System.in);
System.out.println("enter roll no.=");
int roll=Integer.parseInt(dis.readLine());
System.out.println("enter name=");
String name=dis.readLine();
System.out.println("enter mark1=");
int m1=Integer.parseInt(dis.readLine());
System.out.println("enter mark2=");
int m2=Integer.parseInt(dis.readLine());
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3307/studentdb","root","");
PreparedStatement ps=con.prepareStatement("insert into student values (?,?,?,?)");
ps.setInt(1,roll);
ps.setString(2,name);
ps.setInt(3,m1);
ps.setInt(4,m2);
int x=ps.executeUpdate();
System.out.println(x+"row is updated");
con.close();
}
}