[英]Unable to connect to SQL server on localhost
i just keep getting Connection Failed, i dont know why, im running a server on UniServerZ and trying to get the SQL file from localhost. 我只是一直保持连接失败,我不知道为什么,我在UniServerZ上运行服务器并尝试从本地主机获取SQL文件。
Im using uniserverZ (Unicontroller.exe) and i made the .sqlite file using SQLite manager addon for firefox. 我使用uniserverZ(Unicontroller.exe),我使用用于Firefox的SQLite管理器插件制作了.sqlite文件。 Anyone can help me out here?
有人可以帮我吗? Thanks!
谢谢!
Edit: Ok, now im just trying to load the sqlite file from my C drive, i have commented out the command that would load it from my localhost because it doesnt work either. 编辑:好的,现在我只是想从我的C驱动器加载sqlite文件,我已经注释掉了从本地主机加载该命令的命令,因为它也不起作用。 Any help?
有什么帮助吗?
package ui;
import java.sql.*;
import javax.swing.*;
public class MySQLConnect {
Connection conn=null;
public static Connection ConnectDb(){
try{
Class.forName("org.sqlite.JDBC");
Connection conn = DriverManager.getConnection("jdbc:sqlite:C:\\UniServerZ\\home\\Database\\db");
// Connection conn = DriverManager.getConnection("jdbc:mysql:\\localhost:3306\\Database\\db\\student.sql","root","root");
JOptionPane.showMessageDialog(null, "Connection Successful!");
return conn;
} catch(Exception e){
JOptionPane.showMessageDialog(null, "Connection Failed");
return null;
}
}
}
This connection is strange 这个联系很奇怪
jdbc:mysql://localhost:3306//Database//student.sql
try 尝试
"jdbc:mysql://localhost:3306/Database",userName,password
where Database is the real data base name. 其中Database是真实的数据库名称。
Note also single /
vs //
另请注意单
/
vs //
You work with Sqlite database but used the jar of Mysql.. 您使用Sqlite数据库,但使用了Mysql的jar。
So correct this line. 因此,请更正此行。
String driver = "com.mysql.jdbc.Driver";
to 至
String driver = "org.sqlite.JDBC";
Change url and add the sqlite jdbc driver to succesfull connection with Sqlite DB. 更改URL并将sqlite jdbc驱动程序添加到与Sqlite DB的完整连接。
And remove one /
from below line after . 然后从下面的行中删除一个
/
。 jdbc:sqlite:
need only /
. jdbc:sqlite:
仅需要/
。
Connection conn = DriverManager.getConnection("jdbc:sqlite://localhost/Database/db/database.sqlite");
Thanks.. 谢谢..
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.