-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDb.java
46 lines (46 loc) · 1.17 KB
/
Db.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
import java.sql.*;
import java.util.*;
public class Db {
public static void main(String[] args)
{
try{
//Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection c=DriverManager.getConnection("jdbc:ucanaccess://C:/Users/Jaydeep/Documents/java2.accdb");
String q1="insert into t1 values(?,?)";
PreparedStatement pre=c.prepareStatement(q1);
Statement s=c.createStatement();
Scanner sc=new Scanner(System.in);
int a=sc.nextInt();
while(a!=0)
{
a=sc.nextInt();
pre.setInt(1,a);
pre.setInt(2,a);
int su=pre.executeUpdate();
}
/*String q="select * from t1";
s.execute(q);
ResultSet rs=s.getResultSet();
while(rs.next())
{
System.out.println(rs.getString(1)+" "+rs.getString(2));
}*/
String q3="create table t2(num number)";
//String q4="insert into t1 values(20,20)";
//String q5="alter table t1 add num number";
int i=s.executeUpdate(q3);
//i=s.executeUpdate(q4);
//i=s.executeUpdate(q5);
String q2="select Name from t1";
s.execute(q2);
ResultSet rs=s.getResultSet();
while(rs.next())
{
System.out.println(rs.getString(1));
}
}catch(Exception e)
{
System.out.println(e);
}
}
}