db에서 데이터를 읽고 애플릿에 표시 한 Java 애플릿 클래스를 생성했습니다. 프로그램을 올바르게 실행하고 내가 이클립스 IDE에서 실행할 때 데이터를 가져온다 있지만 브라우저에서 HTML 코드를 사용하여 실행할 때 실행되지만 있지만 DB에서 데이터를 가져 오지 않습니다. 이것은 내가 사용하는 코드입니다.애플릿이 브라우저에서 실행 중일 때 MySQL 데이터베이스에서 데이터를 읽지 않습니다.
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Date;
import javax.swing.JApplet;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
import javax.swing.JLabel;
public class Driver extends JApplet {
private Connection connect = null;
private Statement statement = null;
private PreparedStatement preparedStatement = null;
private ResultSet resultSet = null;
private JLabel lbl = null;
private String label;
public void init() {
try {
try {
// this will load the MySQL driver, each DB has its own driver
Class.forName("com.mysql.jdbc.Driver");
// setup the connection with the DB.
connect = DriverManager
.getConnection("jdbc:mysql://localhost/jdbc?"
+ "user=root&password=");
// statements allow to issue SQL queries to the database
statement = connect.createStatement();
// resultSet gets the result of the SQL query
resultSet = statement
.executeQuery("select * from jdbc.info");
// writeResultSet(resultSet);
while (resultSet.next()) {
String user = resultSet.getString("id");
String name = resultSet.getString("name");
label = user +" "+ name;
}
} catch (Exception e) {
throw e;
} finally {
// close();
}
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
lbl = new JLabel(label);
add(lbl);
}
});
} catch (Exception e) {
System.err.println("createGUI didn't complete successfully");
}
}
public static void main(String[] args) throws Exception {
Driver dao = new Driver();
dao.init();
}
}
는 그리고이
<html>
<head>
<title>My first app reding from db</title>
</head>
<body>
My first app reding from db<br />
<applet code="jdbcdemo/Driver.class" width="700" height="700" />
</body>
</html>
사람이 애플릿이 로컬 WAMP 서버에있는 데이터베이스에서 읽기되지 않는 이유 나를 찾는 데 도움이 될 수있는 HTML 코드를입니다. 그 (것)들을 달리기 위하여 .Class를 추가해야하는 그들의 특정한 디렉토리는 무엇인가?
어떤 오류가 발생합니까? 연결 문자열의 localhost가 정확하지 않습니다. 데이터베이스 서버의 IP 주소 또는 도메인 이름이어야합니다. localhost는 db-server가 아닌 client-machine을 가리 킵니다. 누군가가 서버에서 애플릿을 탐색 중이면 (물리적으로 앉아있는 경우) – Yazan
그것은 특별한 오류가 아니며 단지 데이터를 표시하지 않습니다. 난 그냥 변경하고 내 서버 IP를 추가했지만 여전히 작동하지 않습니다. – user2489592
애플릿을 시작하기 전에'throw e;'바로'e.printStacktrace();'를 사용하고 애플릿을 시작하기 전에 Java 콘솔을 엽니 다. (콘트롤 패널에서 생각합니다) – Yazan