Repository navigation
Expand file tree
/
Copy pathjdbc.java
More file actions
92 lines (80 loc) · 2.05 KB
/
Copy pathjdbc.java
File metadata and controls
92 lines (80 loc) · 2.05 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package sharefile;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.StringTokenizer;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author seema
*/
public class jdbc {
/**
* @param args the command line arguments
*/
private String url = "jdbc:mysql://localhost:3306/fileshare";
private String driver = "com.mysql.jdbc.Driver";
private String userName = "root";
private String password = "";
private Connection con = null;
private Statement stmt = null;
public jdbc(){
con = this.getConnection();
}
public Connection getConnection() {
try {
Class.forName(driver);
if(con == null){
con = DriverManager.getConnection(url,userName,password);
}
System.out.print("Connection estd");
}catch (Exception e) {
System.out.print("Error : " +e.getMessage());
}
return con;
}
public void execute(String sql)
{
try
{
System.out.println("Creating statement...");
stmt = con.createStatement();
//sql = "SELECT id, first, last, age FROM Employees";
stmt.executeUpdate(sql);
stmt.close();
}
catch(SQLException s)
{
s.printStackTrace();
}
}
public void search(String sql,ResultSet[]rset1)
{
ResultSet rs = null;
try
{
stmt=con.createStatement();
rs=stmt.executeQuery(sql);
rset1[0]=rs;
}
catch(Exception e)
{
e.printStackTrace();
}
//return rs;
}
}