我创建了一个远程数据库in this website
然后我创建了一个表
之后,我尝试使用此Java代码连接到我的远程数据库:
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try{
Connection con = DriverManager.getConnection("jdbc:mysql://www.000webhost.com/id1538634_mydrive","root","id1538634_root");
PreparedStatement ps = con.prepareStatement("insert into membre(name,pseudo,pw,profilephoto) values(?,?,?,?)");
FileInputStream is = new FileInputStream(new File(s));
ps.setString(1, t1.getText());
ps.setString(2, t2.getText());
ps.setString(3, pw);
ps.setBinaryStream(4, (InputStream)is, (int)( new File(s).length() ));
ps.executeUpdate();
JOptionPane.showMessageDialog(null, "Registration with success");
}catch(Exception ex){
ex.printStackTrace();
}
编译时,我什么也得不到。没有异常也没有错误,也没有插入数据。
答案 0 :(得分:0)
您必须对my.cnf
文件进行以下更改
`my.cnf`
bind-address = www.000webhost.com (OR)
bind-address = xx.xx.xx.xx (IP Address)
如果您没有任何用户登录问题,您应该能够从Java代码连接到MySQL数据库。