forked from mishrkavita/Online-Banking-System-using-Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDBConnection.java
More file actions
72 lines (61 loc) · 2.28 KB
/
DBConnection.java
File metadata and controls
72 lines (61 loc) · 2.28 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
/******************************************************************************
* Program Author: Dr. Yongming Tang for CSCI 6810 Java and the Internet *
* Date: September, 2012 *
*******************************************************************************/
package com.mishra;
import java.util.*;
import java.sql.*;
public class DBConnection {
private Connection connection;
private String URL;
public DBConnection() {
//URL = "jdbc:odbc:JavaClass";
URL ="jdbc:sqlserver://127.0.0.1:1433;databaseName=JavaClass;integratedSecurity=true;";//"user=tang;password=;
connection = null;
}
public Connection openConn() {
try {
//Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
connection = DriverManager.getConnection(URL);
//connection = DriverManager.getConnection(URL, "tang", "xxxxxx");
}
catch ( Exception e ) {
e.printStackTrace();
connection = null;
}
return connection;
}
public void closeConn() {
try {
connection.close();
}
catch( Exception e ) {
System.err.println ("Can't close the database connection.");
}
}
public Vector getNextRow(ResultSet rs,ResultSetMetaData rsmd) throws SQLException
{
Vector currentRow = new Vector();
for(int i=1;i<=rsmd.getColumnCount();i++)
switch(rsmd.getColumnType(i))
{
case Types.VARCHAR:
case Types.LONGVARCHAR:
currentRow.addElement(rs.getString(i));
break;
case Types.INTEGER:
currentRow.addElement(new Long(rs.getLong(i)));
break;
case Types.DOUBLE:
currentRow.addElement(new Double(rs.getDouble(i)));
break;
case Types.FLOAT:
currentRow.addElement(new Float(rs.getFloat(i)));
break;
default:
System.out.println("Type was: "+ rsmd.getColumnTypeName(i));
}
return currentRow;
}
}