1

我通过 lan 2 计算机连接。fisrt pc 是服务器并安装了 wamp 服务器。我通过浏览器从客户端 PC 使用该服务器。但是我的java程序连接到服务器。并且没有任何错误。帮我。这是我的代码剪断:

public class dataconnection {

public Connection getDBConnection() throws Exception {
    Connection conn = null;
    Class.forName("com.mysql.jdbc.Driver").newInstance();

    String sURL = "jdbc:mysql://192.168.0.102:8081/db_name?useUnicode=true&characterEncoding=UTF-8";
    String sUserName = "root";
    String sPwd = "pass";
    conn = DriverManager.getConnection(sURL, sUserName, sPwd);
    return conn;
}
}

这里是:app.class

try {
            dataconnection datacon = new dataconnection();
            String customername = jTextField1.getText();
            String organization = jTextField2.getText();
            String serialkey = jTextField3.getText();
            GetMacAddress();
            String sql = "Select data from cols where id='" + id + "'";
            Connection con = datacon.getDBConnection();
            PreparedStatement ps = con.prepareStatement(sql);
            ResultSet rs = ps.executeQuery();
            if (!rs.next()) {
                JOptionPane.showMessageDialog(null,
                        "Invalid",
                        "Error",
                        JOptionPane.ERROR_MESSAGE);
            }

否则 { bla bla ... }

4

0 回答 0