0

I was trying to connect JSP to MySQL and the server am using is Xamp's Tomcat, but all in vain, i have watched all tutorials but they are not working. 1: i have installed JDBC connector too. 2: am working in NET BEANS

files am importing are

<%@ page import="java.util.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.io.*" %>

and the method am using is

<%
Connection conn = null; 
Statement st = null; 
ResultSet rs = null;
Class.forName("com.mysql.jdbc.Driver").newInstance(); 
conn = DriverManager.getConnection("jdbc:mysql://localhost/userdetails"); 
st = conn.createStatement();

rs = st.executeQuery("select * from user"); 
while(rs.next()) { %>
<tr>
    <td><% rs.getString("id"); %></td><td><% rs.getString("idd"); %></td>
</tr>  

    <% }

%>

and is there any proper way to come to know what is the main error? because i am really not getting it, where am wrong

I have tried jdbc:mysql://localhost:3306/userdetails also.

Juanid Farooq
  • 93
  • 1
  • 1
  • 7
  • Make sure to add the JDBC connector in WEB-INF/lib folder. If such folder doesn't exists, create it and then add the jar. – Luiggi Mendoza Aug 25 '14 at 14:50
  • You are missing the username and password for the db... is that correct? – luanjot Aug 25 '14 at 14:52
  • 2
    Also, you should connect to database from a Java class, **NEVER** from JSP directly. Read more about it here: [How to avoid Java Code in JSP-Files?](http://stackoverflow.com/q/3177733/1065197). And, **NEVER** use scriptlets, not even for learning purposes, only for quick dirty tests that will be removed as soon as possible. – Luiggi Mendoza Aug 25 '14 at 14:52
  • any exceptions raised? – Abhishek Nayak Aug 25 '14 at 15:22

0 Answers0