0
JDBC-MySQL驅動程序已正確安裝並且連接完全正常工作。JSP/MySQL(JDBC) - Select語句給出空結果
我已經插入了創建的數據庫,表,插入行和從視圖數據我已經執行了選擇語句。那些工作正常。但是在這段代碼中,只有INSERT聲明正在工作並且加入結果SELECT聲明不是。 在互聯網上搜索幾小時後,我也沒有線索。
這裏是代碼 -
<%@ page import="java.sql.*" %>
<%@ page import="java.io.*" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%
String connectionURL = "jdbc:mysql://localhost:3306/users";
Connection connection = null;
Class.forName("com.mysql.jdbc.Driver").newInstance();
connection = DriverManager.getConnection(connectionURL, "root", "pass");
if (!connection.isClosed()) {
out.println("Connection Established");
PreparedStatement preparedStmt = connection.prepareStatement("INSERT INTO users.user_details (`Email`, `Name`, `Password`) VALUES ('[email protected]', 'Ram Das', '12345678')");
preparedStmt.execute();
String sql="select * from user_details";
PreparedStatement statement=connection.prepareStatement(sql);
ResultSet rs=statement.executeQuery();
if(rs.next())
{
System.out.println(rs.getString(1));
}
}
connection.close();
%>
你用'System.out'代替了。 ist打印在控制檯中? – SilverNak
@SilverNak,哈哈,謝謝,我只是忽略了它。我的錯。 – RupamDotInfo