Java & Local Databases

前端 未结 4 1329
耶瑟儿~
耶瑟儿~ 2021-01-04 13:47

TL DR; Want some Java help with connecting to a truly local database ( no access to server tech ), or if you can whip up code, that will work. All it has to do is query the

4条回答
  •  隐瞒了意图╮
    2021-01-04 13:57

    As a follow up to Oscar...

    Here's a simple "Type in the SQL" JSP page, using JSTL (Java Standard Tag Library) tags.

    All you need to make this work is toss in the derby.jar library.

    Download tomcat from Apache.

    Download derby from Apache

    cd $TOMCAT_HOME/webapps

    mkdir yourapp

    cd yourapp

    Take the following and put it in index.jsp:

    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
    <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
    <%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql"%>
    
    
    
    
        
            
            SQL Fun
        
        
            

    Welcome to Derby SQL


    Executing: ${param.sql}
    ${param.sql} Result = ${result} ${param.sql}

    mkdir WEB-INF

    take the following and put it in web.xml

    
    
        
            index.jsp
        
    
    

    mkdir WEB-INF/lib

    copy the derby.jar in to WEB-INF/lib

    You should now have 3 files:

    $TOMCAT_HOME/webapps/yourapp/index.jsp $TOMCAT_HOME/webapps/yourapp/WEB-INF/web.xml $TOMCAT_HOME/webapps/yourapp/WEB-INF/lib/derby.jar

    Now fire up Tomcat, and point your browser at http://localhost:8080/yourapp

    And you'll get this little box to type SQL in to.

    Derby will create the DB for you automagically.

    With the JSTL and SQL tags you can do all you want from straight JSP.

    Is it "best practice" to do everything in JSP? No.

    Does it work? Yes.

    Is it practical? Yes.

    You can always change it later.

提交回复
热议问题