-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjava_database.java
More file actions
35 lines (28 loc) · 891 Bytes
/
java_database.java
File metadata and controls
35 lines (28 loc) · 891 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
32
33
34
35
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.ResultSet;
public class Hello
{
public static void main(String arg[]) throws SQLException{
{ String JDBC_DRIVER="com.mysql.jdbc.Driver";
String host="jdbc:mysql://localhost:3306/temp";
String user_name="root";
String password="";
Connection con=DriverManager.getConnection(host,user_name,password);
Statement stmt=null;
ResultSet rs;
stmt = con.createStatement();
rs=stmt.executeQuery("select * from dmp");
while(rs.next())
{
String n=rs.getString("name");
int i=rs.getInt("id");
System.out.println("ID is: "+i);
System.out.println("name is: "+n);
}
}
}
}