Jump to content

Connecting to Database


MassRS

Recommended Posts

So i'm having problems with connecting to my MS Access database with UcanAccess.

I found this snippet on google:

// variables
        Connection connection = null;
        Statement statement = null;
        ResultSet resultSet = null;

        // Step 1: Loading or registering Oracle JDBC driver class
        try {
        	Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");//Loading Driver
        	
        }
        catch(ClassNotFoundException cnfex) {

            log("Problem in loading or "
                    + "registering MS Access JDBC driver");
            cnfex.printStackTrace();
        }

        // Step 2: Opening database connection
        try {

        	log("TRYING TO CONNECT DB");
            String msAccDB = "C:\\Database\\DB1.accdb";
            String dbURL = "jdbc:ucanaccess://" + msAccDB; 

            // Step 2.A: Create and get connection using DriverManager class
            connection = DriverManager.getConnection(dbURL); 

            // Step 2.B: Creating JDBC Statement 
            statement = connection.createStatement();

            // Step 2.C: Executing SQL & retrieve data into ResultSet
            resultSet = statement.executeQuery("SELECT * FROM bots");

            // processing returned data and printing into console
            while(resultSet.next()) {
            	log("DB CONNECTED");
                log(resultSet.getInt(1) + "\t" + 
                        resultSet.getString(2) + "\t" + 
                        resultSet.getString(3) + "\t" +
                        resultSet.getBoolean(4) + "\t" +
                        resultSet.getBoolean(5));
            }
        }
        catch(SQLException sqlex){
            sqlex.printStackTrace();
        }

 

But i can't seem to succesfully load the driver, i get this message in the log:

[INFO][Bot #1][09/20 10:02:27 PM]: Problem in loading or registering MS Access JDBC driver
[INFO][Bot #1][09/20 10:02:27 PM]: TRYING TO CONNECT DB

I have the .jar's from UcanAccess.

I've tried the following already:

- Place the .jar's in the Eclipse workspace. 

- Place the .jar's in the Eclipse workspace in my package folder. 

- Imported the .jar's in Eclipse as External jar's.

 

Can't seem to figure this out..

 

Link to comment
Share on other sites

22 minutes ago, Knuckolls said:

did you manage to comfobble the mainframe and deltoid the flux capacitor?

I did that and it worked.

<3

I did that for my wireless energy transfering module wich shoots electro beams in to the ionosphere and had my cat work as receiver.

It worked then... But didnt work for this.

 

Ly2

Link to comment
Share on other sites

Try following these instructions:

 

Quote

 

I created a folder on my Desktop and put in the following:

  • osbot-sql/
  • osbot-sql/lib/<YOUR DB CONNECTOR JAR FILE>
  • osbot-sql/lib/OSBot 2.5.8.jar
  • osbot-sql/Start OSBot with SQL Driver.bat

The contents of the batch file is as follows:


"C:\Program Files\Java\jre1.8.0_172\bin\java.exe" -cp "lib/*" org.osbot.Boot -debug

 The first bit "C:\...\..\..\" can be changed to just "java" if your running version of Java is compatible with OSBot. Mine isn't. If yours is, then you can simply do the following:


java -cp "lib/*" org.osbot.Boot -debug

 

 
Edited by liverare
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...