|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object javax.servlet.jsp.tagext.TagSupport cmu.survey.jsp.tags.DatabaseConnection
public class DatabaseConnection
Connects to several different types of databases, and is used for most survey tags. It will probably handle anything that JDBC does, but it has been tested only with the following two:
- MYSQL
(www.MySQL.com, a free, good, database)
- MS_ACCESS
(Microsoft Access)
For example, to connect to a MySQL database, with the database named "databaseName", user "userName", and password "usersPassword", use one of the following:
You can use this as a JSP tag:
<%@ taglib uri="/WEB-INF/SurveyTags.tld" prefix="survey" %>
<survey:connection databaseName="jdbc:mysql://localhost:3306/databaseName?user=userName&password=usersPassword">
</survey:connection>
Or from regular Java code:
cmu.survey.DatabaseConnection connection = new cmu.survey.DatabaseConnection();
connection.setDatabaseName("jdbc:mysql://localhost:3306/databaseName?user=userName&password=usersPassword");
connection.doStartTag();
Field Summary | |
---|---|
protected java.lang.String |
databaseConnectionString
|
protected int |
databaseType
|
static int |
MS_ACCESS
|
static int |
MYSQL
|
static int |
ODBC
|
protected javax.servlet.jsp.JspWriter |
out
|
protected javax.servlet.http.HttpSession |
session
|
protected java.sql.Connection |
theConnect
|
protected javax.servlet.http.HttpServletRequest |
theRequest
protected so that subclasses can use it if needed. |
Fields inherited from class javax.servlet.jsp.tagext.TagSupport |
---|
id, pageContext |
Fields inherited from interface javax.servlet.jsp.tagext.IterationTag |
---|
EVAL_BODY_AGAIN |
Fields inherited from interface javax.servlet.jsp.tagext.Tag |
---|
EVAL_BODY_INCLUDE, EVAL_PAGE, SKIP_BODY, SKIP_PAGE |
Constructor Summary | |
---|---|
DatabaseConnection()
|
Method Summary | |
---|---|
boolean |
checkSQLFieldValid(java.lang.String sqlFieldName)
Throws a runtime exception if there is a bad field name. |
static java.lang.String |
cleanString(java.lang.String sqlString)
We clean this string by clearing out all values that need to be escaped out. |
java.lang.String |
cleanStringBetter(java.lang.String sqlString)
We clean this string by clearing out all values that need to be escaped out. |
static java.lang.String |
cleanStringThatShouldHaveBeenClean(java.lang.String sqlString,
javax.servlet.jsp.PageContext pageContext)
|
void |
close()
|
void |
doCatch(java.lang.Throwable throwable)
|
boolean |
doConnection()
|
int |
doEndTag()
This function closes the connection when the ending tag is encountered |
void |
doFinally()
|
int |
doStartTag()
This function opens a connection to the requested database when the tag is first encountered |
void |
finalize()
|
java.sql.Connection |
getConnect()
|
static DatabaseConnection |
getDatabaseConnectionFrom(java.lang.String databaseName)
|
java.lang.String |
getDatabaseName()
Returns the database connection string. |
java.lang.String |
getDatabaseProgramName()
Returns the name of this database program. |
int |
getDatabaseType()
|
static java.lang.String |
getDebuggingInfo()
|
java.lang.String |
getHelpURL()
Returns a URL with help about installing, starting, and stopping this database program. |
java.lang.Throwable |
getLastExceptionThrown()
|
java.lang.String |
getMySqlDatabaseHost()
This isn't terribly accurate or adaptable right now. |
java.lang.String |
getMySqlDatabaseName()
This isn't terribly accurate or adaptable right now. |
java.lang.String |
getMySqlDatabasePassword()
This isn't terribly accurate or adaptable right now. |
java.lang.String |
getMySqlDatabaseUser()
This isn't terribly accurate or adaptable right now. |
javax.servlet.http.HttpSession |
getSession()
|
static java.lang.String |
getThisFolderURL(javax.servlet.jsp.PageContext pageContext)
Get the URL with just the folder, as in: http://blahblah.com:8080/survey/ |
static java.lang.String |
getThisFullURL(javax.servlet.jsp.PageContext pageContext)
Get Full URL -- as in http://blahblah.com:8080/survey/page1.jsp |
static java.lang.String |
getURLFileName(javax.servlet.jsp.PageContext pageContext)
|
boolean |
initializeAtStartTag()
|
boolean |
isOpen()
|
static java.lang.Number |
parseAndCleanNumberStringThatShouldHaveBeenClean(java.lang.String sqlString)
|
static java.lang.Number |
parseAndCleanNumberStringThatShouldHaveBeenCleanStatic(java.lang.String sqlString)
|
void |
reinit()
|
protected void |
saveBugMessage(java.lang.String error)
|
protected void |
saveBugMessage(java.lang.String error,
java.lang.Throwable e)
|
protected void |
saveNotificationMessage(java.lang.String error)
|
protected void |
saveNotificationMessage(java.lang.String error,
java.lang.Throwable e)
|
void |
setDatabaseName(java.lang.String newDatabaseName)
|
void |
setHttpServletRequest(javax.servlet.http.HttpServletRequest request)
|
void |
setLastExceptionThrownToNull()
|
void |
setPageContext(javax.servlet.jsp.PageContext context)
|
void |
setSendErrorMessages(boolean emailTheErrorMessages)
|
Methods inherited from class javax.servlet.jsp.tagext.TagSupport |
---|
doAfterBody, findAncestorWithClass, getId, getParent, getValue, getValues, release, removeValue, setId, setParent, setValue |
Methods inherited from class java.lang.Object |
---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected java.sql.Connection theConnect
protected java.lang.String databaseConnectionString
protected int databaseType
public static final int MYSQL
public static final int MS_ACCESS
public static final int ODBC
protected javax.servlet.jsp.JspWriter out
protected javax.servlet.http.HttpSession session
protected javax.servlet.http.HttpServletRequest theRequest
Constructor Detail |
---|
public DatabaseConnection()
Method Detail |
---|
public static java.lang.String getDebuggingInfo()
public java.sql.Connection getConnect()
public static DatabaseConnection getDatabaseConnectionFrom(java.lang.String databaseName)
public static final java.lang.String getThisFullURL(javax.servlet.jsp.PageContext pageContext)
public static final java.lang.String getThisFolderURL(javax.servlet.jsp.PageContext pageContext)
pageContext
-
public static final java.lang.String getURLFileName(javax.servlet.jsp.PageContext pageContext)
public static final java.lang.String cleanStringThatShouldHaveBeenClean(java.lang.String sqlString, javax.servlet.jsp.PageContext pageContext)
public static final java.lang.Number parseAndCleanNumberStringThatShouldHaveBeenCleanStatic(java.lang.String sqlString)
public static java.lang.Number parseAndCleanNumberStringThatShouldHaveBeenClean(java.lang.String sqlString)
public java.lang.String cleanStringBetter(java.lang.String sqlString)
public static final java.lang.String cleanString(java.lang.String sqlString)
public boolean checkSQLFieldValid(java.lang.String sqlFieldName)
public java.lang.String getDatabaseName()
public void setDatabaseName(java.lang.String newDatabaseName)
public int getDatabaseType()
public java.lang.String getDatabaseProgramName()
public java.lang.String getHelpURL()
public java.lang.String getMySqlDatabaseHost()
public java.lang.String getMySqlDatabaseName()
public java.lang.String getMySqlDatabaseUser()
public java.lang.String getMySqlDatabasePassword()
public javax.servlet.http.HttpSession getSession()
public void setHttpServletRequest(javax.servlet.http.HttpServletRequest request)
public void setPageContext(javax.servlet.jsp.PageContext context)
setPageContext
in interface javax.servlet.jsp.tagext.Tag
setPageContext
in class javax.servlet.jsp.tagext.TagSupport
public void setSendErrorMessages(boolean emailTheErrorMessages)
public java.lang.Throwable getLastExceptionThrown()
public void setLastExceptionThrownToNull()
protected void saveBugMessage(java.lang.String error, java.lang.Throwable e)
protected void saveBugMessage(java.lang.String error)
protected void saveNotificationMessage(java.lang.String error, java.lang.Throwable e)
protected void saveNotificationMessage(java.lang.String error)
public boolean isOpen()
public boolean doConnection()
public boolean initializeAtStartTag()
public void close()
public void finalize()
finalize
in class java.lang.Object
public int doStartTag()
doStartTag
in interface javax.servlet.jsp.tagext.Tag
doStartTag
in class javax.servlet.jsp.tagext.TagSupport
public int doEndTag()
doEndTag
in interface javax.servlet.jsp.tagext.Tag
doEndTag
in class javax.servlet.jsp.tagext.TagSupport
public void doCatch(java.lang.Throwable throwable)
doCatch
in interface javax.servlet.jsp.tagext.TryCatchFinally
public void doFinally()
doFinally
in interface javax.servlet.jsp.tagext.TryCatchFinally
public void reinit()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |