Got error while I'm tried to connect database

java database

34 просмотра

2 ответа

Got error while I'm tried to connect SQL database using cmd. Here is my program.I use jdk 6 version to compile and run Thanks in Advance.

import java.sql.*;

class Dbs
   public static void main(String args[]) throws Exception
       Connection con = null;
       Statement s = null;
       ResultSet rs = null;

       String bala = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=c:\\ss.mdb";

        con = DriverManager.getConnection(bala,"","");
        s = con.createStatement();
        rs =s.executeQuery("select * from Table1");


     catch(Exception e)


enter image description here

Автор: Bala555 Источник Размещён: 08.11.2019 10:55

Ответы (2)

1 плюс

Are you in the correct directory ? It seems you are in your jdk directory, where you should be in your program's directory (where your Dbs.class resides).

Also, you missed the public keyword. Here, your Dbs is package local, so it won't be visible outside the package. Depending on where you use it, it may trigger the error.


public class Dbs {
   // code


If you don’t explicitly specify a package, your classes and interfaces end up in an unnamed packaged, also known as the default package. Best practice is not to use the default package for any production code.

more here.

Автор: Derlin Размещён: 20.08.2016 05:39

0 плюса

the error says the class you are trying to get is not where it must, check the the jdbc driver is in the correct place ,check if you have your JAVA_PATH set and put a try catch to see if there is another error who is causing that

Автор: Pavul Zavala Размещён: 20.08.2016 05:47
Вопросы из категории :