2014-03-06 238 views
0

我只是不斷收到連接失敗,我不知道爲什麼,即時通訊在UniServerZ上運行服務器,並嘗試從本地主機獲取SQL文件。無法連接到本地主機上的SQL服務器

使用uniserverZ(Unicontroller.exe)我使用SQLite管理器插件爲Firefox做了.sqlite文件。任何人都可以幫助我嗎?謝謝!

編輯:好的,現在我只是試圖從我的C驅動器加載sqlite文件,我已經註釋掉將從我的本地主機加載它的命令,因爲它也不工作。任何幫助?

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; 
      } 
     } 
} 
+1

您可以發佈'e.printStackTrace();'? – Incognito

+0

你確定你的SqlLite數據庫文件在哪裏?你的代碼是否有權訪問它? SqlLite的補丁對我來說看起來很奇怪。 SqlLite有我認爲的一個文件的形式。你確定你有在SQL lite驅動上的classpatch庫嗎? – RMachnik

+0

爲什麼一切都被稱爲「MySQL」?數據庫文件的實際路徑是什麼? –

回答

0

這種連接是奇怪

jdbc:mysql://localhost:3306//Database//student.sql 

嘗試

"jdbc:mysql://localhost:3306/Database",userName,password 

其中數據庫是真正的數據庫名。

還要注意單/ VS //

1

您與SQLite數據庫的工作,但使用的MySQL JAR ..

所以正確的這條線。

String driver = "com.mysql.jdbc.Driver"; 

String driver = "org.sqlite.JDBC"; 

變更網址和SQLite的JDBC驅動程序添加到使用SQLite數據庫succesfull連接。

然後從下面一行刪除一個/jdbc:sqlite:只需要/

Connection conn = DriverManager.getConnection("jdbc:sqlite://localhost/Database/db/database.sqlite"); 

謝謝..

相關問題