2013-04-05 116 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

相关问题