-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb.java
More file actions
71 lines (54 loc) · 1.62 KB
/
Copy pathdb.java
File metadata and controls
71 lines (54 loc) · 1.62 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package chat;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Date;
import java.sql.Timestamp;
/**
*
* @author Gowtham
*/
public class db {
static private Connection connect = null;
static private Statement statement = null;
static private PreparedStatement preparedStatement = null;
static private ResultSet resultSet = null;
static void pushdata(int userid, String g, Timestamp t)throws Exception{
Class.forName("com.mysql.jdbc.Driver");
// Setup the connection with the DB
connect = DriverManager
.getConnection("jdbc:mysql://localhost/stacke?"
+ "user=sqler&password=sqluser");
// Statements allow to issue SQL queries to the database
statement = connect.createStatement();
resultSet = statement
.executeQuery("select * from stacke.messages");
preparedStatement = connect
.prepareStatement("insert into stacke.messages values ( ? , ?, ?)");
preparedStatement.setInt(1, userid);
preparedStatement.setString(2, g);
preparedStatement.setTimestamp(3, t);
preparedStatement.executeUpdate();
}
void close() {
try {
if (resultSet != null) {
resultSet.close();
}
if (statement != null) {
statement.close();
}
if (connect != null) {
connect.close();
}
} catch (Exception e) {
}
}
}