我的自签名小程序在小程序查看器和本地 Web 浏览器上完美运行。但是,当我根据网站服务器上的mysql数据库的db名称、用户和密码更改连接字符串并通过ftp将项目上传到服务器时,小程序无法连接到数据库。小程序代码为:
public void init() {
JPanel panel = new JPanel();
panel.add( new JLabel("Start"));
revalidate();
// TODO start asynchronous download of heavy resources
String driver = "com.mysql.jdbc.Driver";
String url = "jdbc:mysql://www.mywebiste.com:3306/database";
String user = "user";
String password = "password";
try {
Class.forName(driver);
Connection con = DriverManager.getConnection(url,user,password);
String sql4 = "Select * from form where Il='Ankara'";
//System.out.println(password + " " + userName);
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(sql4);
panel.add( new JLabel("Connection"));
revalidate();
}
catch(Exception e) {
panel.add( new JLabel("Not Connected"));
revalidate();
}
Container content = getContentPane();
content.setLayout(new GridBagLayout());
content.add(panel);
}