-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathmySqlJava.java
More file actions
50 lines (42 loc) · 1.18 KB
/
mySqlJava.java
File metadata and controls
50 lines (42 loc) · 1.18 KB
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
package javadb;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class mySqlJava {
public static void main(String[] args) throws SQLException {
// TODO Auto-generated method stub
Connection con = null;
try {
Class.forName("com.mysql.cj.jdbc.Driver");
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root");
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("select * from employee");
while(rs.next())
{
System.out.println(rs.getInt(1)+ " "+ rs.getString(2) + " "+ rs.getString(3)+" "+ rs.getString(4)+" " + rs.getInt(5) );
}
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally {
con.close();
}
int xc[]=new int[3];
xc[0]=22;
xc[1]=21;
xc[2]=22;
try {
for(int i=0;i<4;i++)
{
System.out.println(xc[i]);
}
} catch (ArrayIndexOutOfBoundsException e) {
// TODO Auto-generated catch block
//e.printStackTrace();
System.out.println("Please check the limit of array " + e);
}
}
}