What is wrong in the code
Data not getting retrieved from database table with below code , What going wrong pls advise.........
HTML Code:
<%@ page language="java" import="java.sql.*;"%>
<html>
<head>
<style>
A:hover {
text-decoration: none;
font-family:arial;
font-size:12px;
color: #000000;
BORDER: none;
}
A {
text-decoration: underline;
font-family:arial;
font-size:12px;
color: #000000;
BORDER: none;
}
</style>
</head>
<body>
<br><br><br>
<%
Connection conn = null;
String url = "jdbc:mysql://localhost:3306/";
String dbName = "bank";
String driver = "com.mysql.jdbc.Driver";
String username = "root";
String userPassword = "java";
String color = "#F9EBB3";
String date = request.getParameter("value");
try {
Class.forName(driver).newInstance();
conn = DriverManager.getConnection(url + dbName, username,
userPassword);
Statement st = conn.createStatement();
String strQuery = "select * from transaction";
ResultSet rs = st.executeQuery(strQuery);
%>
<table width="600px" align="center" style="border:1px solid #000000;" >
<tr><td><b>Transaction ID :</b></td><td><%=rs.getInt("transactionId")%></td></tr>
<tr><td><b>Acc No. :</b></td><td><%=rs.getInt("accountNo")%></td></tr>
<tr><td><b>Additional Information :</b></td><td><%=rs.getString("addInfo")%></td></tr>
</table>
<br><br><br>
<table width="600px" align="center" >
<tr><td align="center"><input type="submit" name="Submit" value="Save As Draft"></td>
<td align="center"><input type="submit" name="Submit" value="Sent TO RBI"></td>
<td align="center"><input type="submit" name="Submit" value="PRINT"></td></tr>
<%
System.out.println("Connected to the database");
conn.close();
System.out.println("Disconnected from database");
} catch (Exception e) {
e.printStackTrace();
}
%>
</table>
</body>
</html>
Re: What is wrong in the code
Are you certain that the code is allowing you to connect to the database correctly? Obviously we have no way of testing this.
Re: What is wrong in the code
Yes dude , Code allowing me connect to database but database values not getting displayed??????????
Re: What is wrong in the code
awaiting for reply.................
Re: What is wrong in the code
Try
String strQuery = "select * from transaction;";
instead of
String strQuery = "select * from transaction";
in the try block.