-
Notifications
You must be signed in to change notification settings - Fork 0
/
Databaseconnection
32 lines (25 loc) · 952 Bytes
/
Databaseconnection
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
//you havt install my sql and jar file
import java.io.*;
import java.sql.*;
public class Databaseconnection {
public static void main(String[] args) {
//step 1 create a input stream
DataInputStream dis = new DataInputStream(System.in);
try {
//step 2 Create a Connection
Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/mysql", "root", "mrspidey");
System.out.println(connection);
//step 3 create a statement
Statement st = connection.createStatement();
//step 4 create a query
String query = "insert into mymy()values(\"MRSpidey\");";
//execute the query
st.executeUpdate(query);
connection.close();
System.out.println("Habibi Yeh run Hoti!");
}
catch(Exception e) {
System.out.println("Exception "+e);
}
}
}