2011-07-18 62 views
-1
<%@ 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(); 
     } 
     %> 

同時運行它,越來越沒有數據庫連接的語句作爲輸出也沒有任何exceptions..any print語句執行相關的陳述之前,如果我們把任何聲明數據庫連接後,它不工作.. 即時通訊使用MySQL數據庫,並已將連接器jar文件放在tomcat6/lib ... 請幫我...問題JDBC同時使用的tomcat6

回答

1

我懷疑異常正在被拋出。用out.print(e.getMessage())替換你的e.printStackTrace(),你會看到。

我認爲這是實驗性的應用程序,通過URL傳遞用戶名和密碼,以這種方式訪問​​數據庫遠非最佳實踐。