|
[x]
Posted via EE Mobile
|
|
| Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again. |
|
|
|
|
Asked by aman0711 in Java Programming Language, Java Server Pages (JSP), New to Java Programming
hi Experts,
I have a simple program which updates a table with current date when user logs in.
For some reason the insert QUERY is throwing Error: LAST_LOGIN: invalid identifier, where as I do have a column called LAST_LOGIN ni my table.
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:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
|
package com.si.dao;
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 com.si.dao.*;
public class UserData {
//prod
String url = "jdbc:oracle:thin:@n123.abc.syz.com:1522:o2";
String user = "user1";
String password = "pass1";
String driver = "oracle.jdbc.driver.OracleDriver";
Connection conn= null;
PreparedStatement pstmt = null;
Statement stmt = null;
ResultSet rs = null;
DbConn db = null;
public String getUserAccessType(String userId) {
String accessType = null;
String qry = "SELECT ACCESS_TYPE FROM SIWEB_USERS WHERE lower(ID) = lower('" + userId.toLowerCase() + "') ";
String updateQry = "INSERT INTO SIWEB_USERS (ID, LAST_LOGIN) VALUES ('" + userId.toLowerCase() + "', SYSDATE)";
System.out.println("qry:" + updateQry);
try {
db = new DbConn();
conn = db.getConnection(url, user, password);
stmt = conn.createStatement();
rs = stmt.executeQuery(qry);
if (rs.next()) {
accessType = rs.getString(1);
}
int t = stmt.executeUpdate(updateQry);
} catch (SQLException sqle) {
sqle.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
rs.close();
db.closeResources(stmt, conn);
} catch (Exception e) {
e.printStackTrace();
}
}
return accessType;
}
//new method to check valid user
public boolean isValidUser(String userId) {
boolean valid = false;
String qry = "select ID from SIWEB_USERS where lower(ID) = '" + userId.toLowerCase() + "'";
try {
stmt = conn.createStatement();
rs = stmt.executeQuery(qry);
if (rs.next()) {
valid = true;
}
} catch (SQLException sqle) {
sqle.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
rs.close();
stmt.close();
conn.close();
} catch (Exception e) {
e.printStackTrace();
}
}
return valid;
}
public static void main(String[] args) {
UserData bd = new UserData();
//String user_access_type = bd.getUserAccessType("PP1592");
String user_access_type = bd.getUserAccessType("at7138");
System.out.println(">>>user access type=" + user_access_type);
}
}
|
20091118-EE-VQP-93 - Hierarchy / EE_QW_3_20080625