2013-04-05 68 views
0

我已經在整個互聯網上搜索過這個問題了...我是JDBC的初學者,但是這裏提供的解決方案和其他站點不適合我。我正在使用Eclipse 3.8 ...我已經安裝了mySQL服務器,它正在運行(我運行它使用:sudo service mysql start)...在運行時我得到這個錯誤找不到合適的dbc驅動程序:mysql:// localhost:8080/kholofedb

connecting to psysical database... 


java.sql.SQLException: No suitable driver found for dbc:mysql://localhost:8080/kholofedb 
    at java.sql.DriverManager.getConnection(DriverManager.java:604) 
    at java.sql.DriverManager.getConnection(DriverManager.java:221) 
    at com.psybergate.database.SimbleCode.main(SimbleCode.java:21) 

這裏是我的源代碼:

package com.psybergate.database; 
import java.sql.Connection; 
import java.sql.DriverManager; 
import java.sql.SQLException; 
import java.sql.Statement; 
import java.util.Scanner; 

public class SimbleCode 
{ 

    private static final String USER = "root" , PASS = ""; 


    public static void main(String ...args) 
    { 
     try { 
      String connectionURL =  "dbc:mysql://localhost:8080/kholofedb"; 
       Class.forName("com.mysql.jdbc.Driver"); 
     // Class.forName("org.postgresql.Driver"); 
      System.out.println("connecting to psysical database..."); 
      Connection conn = DriverManager.getConnection(connectionURL , USER , PASS); 

      Statement statement = conn.createStatement(); 
      System.out.println("Connection has been made"); 

      Scanner keyBoardScanner = new Scanner(System.in); 
      System.out.println("Enter table name:"); 
      String tableName = keyBoardScanner.nextLine(); 

      System.out.println("Creating table..."); 
      statement.executeQuery("create table " + tableName + " (name , age ,salary)"); 
      System.out.println("Table successfully created"); 
      System.out.println("Inserting data into the table ..."); 
      statement.executeUpdate("insert into " + tableName + "values (kholofelo , 21 , 9969696)"); 
     } 
     catch (ClassNotFoundException | SQLException e) { 

      e.printStackTrace(); 
     } 

    } 

} 

感謝提前:)

回答

1

你的連接網址應以「爲jdbc:」不是「DBC:」

+0

'通信鏈接失敗 成功發送到服務器的最後一個數據包是0毫秒前。驅動程序尚未收到來自服務器的任何數據包。 \t at sun.reflect.NativeConstructorAccessorImpl.newInstance0' – 2013-04-05 10:06:20

1

連接字符串應該是:

String connectionURL = "jdbc:mysql://localhost:8080/kholofedb"; 
+0

現在我固定的,但我得到當我使用PostgreSQL – 2013-04-05 09:56:46

+1

什麼例外,這也是我所遇到的另一個例外呢?請檢查您的端口,如果它是8080或3306. – AsirC 2013-04-05 09:57:39

+0

我修復它後得到此異常: 通信鏈路故障 成功發送到服務器的最後一個數據包是0毫秒前。驅動程序尚未收到來自服務器的任何數據包。 \t在sun.reflect.NativeConstructorAccessorImpl.newInstance0(本機方法) \t在sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) \t在sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) \t在java.lang.reflect.Constructor.newInstance(Constructor.java:525) \t at com.mysql.jdbc.Util.handleNewInstance(Util.java。 – 2013-04-05 10:00:45

相關問題