با سلام میشه یه راهنمایی بهم بدین من هر کاری کردم موقع اتصال به دیتا بیس ارور میده این کد های منه میشه بگید مشکلش کجاست؟
از آخرین ورژن MySQL و Ubuntu 16.10 استفاده میکنم. یک دیتا بیس با نام testconection ساختم که 3تا آیتم داره ID,user,pass
این ارور رو میده:
can not connect to db! com.mysql.jdbc.Driver
import java.sql.*;
import java.util.logging.Logger;
import java.util.logging.Level;
import javax.swing.JOptionPane;
/**
*
* @author administrat0r
*/
public class connectiontest extends javax.swing.JFrame {
private Connection con = null;
private Statement stmt = null;
private ResultSet resSet = null;
public boolean connect_to_db()
{
try
{
String username ="root";
String password = "123";
String url = "jdbc:mysql://localhost:3306/testconection";
Class.forName("com.mysql.jdbc.Driver").newInstance();
con = DriverManager.getConnection(url, username, password);
return true;
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null, "can not connect to db! "
+e.getMessage());
return false;
}
}
public boolean query_on_db(String _query)
{
try
{
stmt = con.createStatement();
resSet = stmt.executeQuery(_query);
if (resSet.next())
{
return true;
}
else
{
JOptionPane.showMessageDialog(null, "nothing");
return false;
}
}
catch (Exception e)
{
JOptionPane.showMessageDialog(null, "can not run query! "
+e.getMessage());
return false;
}
}
و برای تست درستی یوزر پسورد از کد زیر استفاده کردم
private void btnloginActionPerformed(java.awt.event.ActionEvent evt) {
if(connect_to_db())
{
String uname = usertxt.getText();
String upass = passtxt.getText();
String sql = "select * from users where User='"+uname+"' "
+"and pass='"+upass+"'";
if (query_on_db(sql))
{
JOptionPane.showMessageDialog(null, "ok!");
}
else
{
JOptionPane.showMessageDialog(null, "incorrect info!");
}
}
سلام تقریبا مشکلم حل شد باید MySQL JDBC Driver رو توی library اضافه میکردم ولی مشکل کامل حل نشده توی لوکال وصل میشه ولی وقتی IP میزنم به جای localhost مثلا میزنم 192.168.1.5 کانکت نمیشه کسی راه حلی داره؟؟؟؟؟ :'( :'( :'(
Libraries -> Right click -> Add library... -> MySQL JDBC Driver -> Add Library
این ارور رو میده
can not connect to db! communications link failure
the last packet send successfully to server was 0 milliseconds ago. The driver has not received any packets from the server.
سلام تقریبا مشکلم حل شد باید MySQL JDBC Driver رو توی library اضافه میکردم ولی مشکل کامل حل نشده توی لوکال وصل میشه ولی وقتی IP میزنم به جای localhost مثلا میزنم 192.168.1.5 کانکت نمیشه کسی راه حلی داره؟؟؟؟؟ :'( :'( :'(
Libraries -> Right click -> Add library... -> MySQL JDBC Driver -> Add Library
این ارور رو میده
can not connect to db! communications link failure
the last packet send successfully to server was 0 milliseconds ago. The driver has not received any packets from the server.
چک کنید ببینید allow_remote_login توی تنظیمات MySQL رو غیر فعال کردید یا خیر؟