-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPre_prared_statement.java
61 lines (38 loc) · 1.25 KB
/
Pre_prared_statement.java
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
51
52
53
54
55
56
57
58
59
60
61
package jdbc_1;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Scanner;
import java.io.*;
import java.util.*;
import java.sql.*;
import com.mysql.cj.jdbc.DatabaseMetaData;
public class Pre_prared_statement {
public static void main(String[] args) throws Exception {
String url = "jdbc:mysql://localhost:3306/eee";
String uname = "root";
String pass = "shakil**";
String id = "CE20046";
String name = "FaizaM";
String dept = "CSE";
String balance ="20000";
String query = "insert into student1 values (?,?,?,?)";
Connection con = DriverManager.getConnection(url,uname,pass);
PreparedStatement st = con.prepareStatement(query);
st.setString(1, id);
st.setString(2, name);
st.setString(3, dept);
st.setString(4, balance);
int count = st.executeUpdate();
System.out.println(count + " row's affected");
//Statement st1 = con.createStatement();
//st.executeQuery(query);
//ResultSet rs = st.executeQuery(query);
//ResultSet rs1 = st1.executeQuery(query);
st.close();
con.close();
}
}