开发者

problem with jdbc while using tomcat6

开发者 https://www.devze.com 2023-03-21 15:57 出处:网络
<%@ page language=\"java\" import=\"java.sql.*\"%> <% String username = request.getParameter(\"username\");
    <%@ page language="java" import="java.sql.*"%>

  <%
        String username = request.getParameter("username");
        String password = request.getParameter("password");

         out.println(username+password); //just for checking

Connection conn = null;
ResultSet rst=null;
String url = "jdbc:mysql://localhost:3306/";
String dbName = "olts";
String driver = "com.mysql.jdbc.Driver";
String userName1 = "root"; 
String password1 = "root";
try {

               Class.forName(driver).newInstance();
               conn = DriverManager.getConnection(url+dbName,userName1,password1);
out.println("Connected to the database");
Statement stmt=null;
stmt=conn.createStatement();
String qry = "select * from users where username='" + username  +"' and password='"+password + "'";
rst=stmt.executeQuery(qry);

       out.println(qry);
      conn.close();
        out.println("Disconnected from database");
          } catch(Exception e) {
                 e.printStackTrace();
        }
      %> 

while running it, getting neither database connected statement as output nor 开发者_StackOverflowany exceptions..any print statement before connection statements are executed and if we place any statement after database connection its not working... im using mysql database and already placed the connector jar file in tomcat6/lib... please help me out...


I suspect exceptions are being thrown. Replace your e.printStackTrace() with something like out.print(e.getMessage()) and you will see.

I assume this is experimental application as passing usernames and passwords via URLs, and accessing the database in this fashion is far from best practice.

0

精彩评论

暂无评论...
验证码 换一张
取 消