there is some error like file parsing error while compiling this file in netbeans..if u know any solution than plz let me know it______ import java.io.*; import java.util.*; import javax.sql.*; import javax.servlet.*; import javax.servlet.http.*; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; public class connection extends HttpServlet { @Override public void service(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException{ response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println("<html>"); out.println("<head><title>Servlet JDBC</title></head>"); out.println("<body>"); out.println("<h1>Servlet JDBC</h1>"); out.println("</body></html>"); // connecting to database Connection con = null; Statement stmt = null; ResultSet rs = null; try { Class.forName("com.mysql.jdbc.Driver"); con =DriverManager.getConnection ("jdbc:mysql://192.168.10.59:3306/example","root","root"); stmt = con.createStatement(); rs = stmt.executeQuery("SELECT * FROM servlet"); // displaying records while(rs.next()){ out.print(rs.getObject(1).toString()); out.print("\t\t\t"); out.print(rs.getObject(2).toString()); out.print("<br>"); } } catch (SQLException e) { throw new ServletException("Servlet Could not display records.", e); } catch (ClassNotFoundException e) { throw new ServletException("JDBC Driver not found.", e); } finally { try { if(rs != null) { rs.close(); rs = null; } if(stmt != null) { stmt.close(); stmt = null; } if(con != null) { con.close(); con = null; } } catch (SQLException e) {} } out.close(); } }
want to know how to connect java servlet with mysql
how to connect to mysql Database from servlet?
Thanks dear your code has helped me understand servlet to mysql database communication
very nice explanation of servlet, mysql interaction.
Post your Comment
Using MYSQL Database with JSP & Servlets.
java servlets with database interaction
Mysql connect
how to connect jsp to mysql - Java Beginners
i can not connect to database in servlet - JSP-Servlet
connect to the database from JSP
How to connect to MySql Database from Servlet?
Connect JSP with mysql
servlet7
servlet5
servlet3
servlet4
how to connect mysql with JDBC - JDBC
MYSQL and SERVLETS - JDBC
servlet2
servlet6
Accessing Database from servlets through JDBC!
how to connect mySql drivers into eclipse(configuration)?
pls provide steps to connect mysql database in flex - XML
mysql_connect arguments
how to connect to database in php using mysql
how to connect mysql from gui?
how can i create a mysql database to connect to this code - JDBC
TO connect multiple database
cannot connect to database - JDBC
Servlets mysql connectivity
retrieve data from mysql database
How to connect to MySql Database from ServletNABEEL. AHMAD February 3, 2013 at 12:50 PM
there is some error like file parsing error while compiling this file in netbeans..if u know any solution than plz let me know it______ import java.io.*; import java.util.*; import javax.sql.*; import javax.servlet.*; import javax.servlet.http.*; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; public class connection extends HttpServlet { @Override public void service(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException{ response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println("<html>"); out.println("<head><title>Servlet JDBC</title></head>"); out.println("<body>"); out.println("<h1>Servlet JDBC</h1>"); out.println("</body></html>"); // connecting to database Connection con = null; Statement stmt = null; ResultSet rs = null; try { Class.forName("com.mysql.jdbc.Driver"); con =DriverManager.getConnection ("jdbc:mysql://192.168.10.59:3306/example","root","root"); stmt = con.createStatement(); rs = stmt.executeQuery("SELECT * FROM servlet"); // displaying records while(rs.next()){ out.print(rs.getObject(1).toString()); out.print("\t\t\t"); out.print(rs.getObject(2).toString()); out.print("<br>"); } } catch (SQLException e) { throw new ServletException("Servlet Could not display records.", e); } catch (ClassNotFoundException e) { throw new ServletException("JDBC Driver not found.", e); } finally { try { if(rs != null) { rs.close(); rs = null; } if(stmt != null) { stmt.close(); stmt = null; } if(con != null) { con.close(); con = null; } } catch (SQLException e) {} } out.close(); } }
java servletankit October 20, 2011 at 11:46 AM
want to know how to connect java servlet with mysql
how to connect to mysql Database from servlet?ramkumar March 18, 2012 at 2:03 PM
how to connect to mysql Database from servlet?
Thanks dearjovian July 5, 2012 at 7:58 PM
Thanks dear your code has helped me understand servlet to mysql database communication
mysql servletanurag November 22, 2012 at 4:49 PM
very nice explanation of servlet, mysql interaction.
Post your Comment