-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSdb.java
33 lines (32 loc) · 867 Bytes
/
Sdb.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
//package oracle;
import java.sql.*;
public class Sdb {
public static void main(String[] args) {
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:9999/test","root","");
System.out.println("connection is established");
String str = " INSERT INTO student VALUES (?, ?)";
PreparedStatement p = con.prepareStatement(str);
p.setInt(1,107);
p.setString(2,"abc");
p.executeUpdate();
//String s1="INSERT INTO student VALUES (104,'jay')";
String s="select * from student";
Statement st=con.createStatement();
//st.executeUpdate(s1);
st.execute(s);
ResultSet rs=st.getResultSet();
while(rs.next())
{
System.out.println(rs.getInt(1)+" "+rs.getString(2));
}
}
catch
(Exception e)
{
System.out.println(e);
}
}
}