Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Update sqlTest.java
  • Loading branch information
rmb15004 committed Nov 2, 2016
1 parent 5152e3c commit fd44cd5
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions sqlTest.java
Expand Up @@ -21,21 +21,21 @@ public class sqlTest extends HttpServlet {
private static final long serialVersionUID = 1L;

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
Context ctx = null;
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
Context ctx = null; //context to pull var names from
Connection con = null; //initializes connection
Statement stmt = null; //initializes statement you send for sql
ResultSet rs = null; //initializes resultSet for sql
try{
ctx = new InitialContext();
DataSource ds = (DataSource) ctx.lookup("java:/comp/env/jdbc/LocalStudentAdminDB");
con = ds.getConnection();
stmt = con.createStatement();
rs = stmt.executeQuery("SELECT * FROM SA_Development.TERM");
ctx = new InitialContext();
DataSource ds = (DataSource) ctx.lookup("java:/comp/env/jdbc/LocalStudentAdminDB"); //jdbc lookup
con = ds.getConnection(); //connection from data source
stmt = con.createStatement(); //creates empty statement
rs = stmt.executeQuery("SELECT * FROM SA_Development.TERM"); //results from sql query
PrintWriter out = response.getWriter();

String resultantJSON = "{";
ResultSetMetaData rsmd = rs.getMetaData();
int columnCount = rsmd.getColumnCount();
String resultantJSON = "["; //
ResultSetMetaData rsmd = rs.getMetaData(); //all information that isn't the result #cols #rows
int columnCount = rsmd.getColumnCount();

while(rs.next()){
String individualRow = "{";
Expand All @@ -54,7 +54,7 @@ public class sqlTest extends HttpServlet {
}
resultantJSON += individualRow + "},";
}
resultantJSON += "}";
resultantJSON += "]";
response.setContentType("application/json");
out.print(resultantJSON);
/* response.setContentType("text/html");
Expand Down

0 comments on commit fd44cd5

Please sign in to comment.