Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Connecting to mysql from eclipse
- protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
- Connection con = null;
- try{
- Class.forName("com.mysql.jdbc.Driver").newInstance();
- con = DriverManager.getConnection("jdbc:mysql//localhost:3306/try", "root", "password");
- }catch(Exception e){
- e.printStackTrace();
- }
- if(request.getParameter("select1")!=null){
- PrintWriter out = response.getWriter();
- String select1 = (String) request.getParameter("select1");
- int no = Integer.parseInt(select1);
- String query = "SELECT * FROM try.try where id='"+no+"'";
- out.print("<option>---select one---</option>");
- try{
- Statement stmt = (Statement) con.createStatement();
- ResultSet rs = stmt.executeQuery(query);
- while(rs.next()){
- out.print("<option>"+rs.getString("output")+"</option>");
- }
- }catch(Exception e){
- e.printStackTrace();
- }
- }
- }
- jdbc:mysql://localhost:3306/try
- ^-- you missed the colon here
Add Comment
Please, Sign In to add comment