Jump to content
View in the app

A better way to browse. Learn more.

OSBot :: 2007 OSRS Botting

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

mySQL connection from scripts

Featured Replies

So I am trying to set up a database to connect my scripts together for easier bot-to-bot communication, I've got the code working in java but I can't seem to get it to run in a script, I'm not sure if im being a moron or if it cant be done like this and needs to be done with php.

mySQL codes in database class

then usage in script

Spoiler

 


  public static void post() throws Exception{

		try{
			Connection con = getConnection();
			PreparedStatement posted = con.prepareStatement("INSERT INTO testtable (active, rsn) VALUES (? , ?)");
			posted.setInt(1, var1);
			posted.setString(2, var2);
			posted.executeUpdate();
		} catch(Exception e){System.out.println(e);}
		finally{
			System.out.println("Insert completed");
		}
	}
	
	public static Connection getConnection() throws Exception{
		try{
			String driver = "com.mysql.jdbc.Driver";
			String url = "jdbc:mysql://(sqlip):3306/(database)?";
			String username = "(user)";
			String password = "(pass)";
			Class.forName(driver);
			
			Connection conn = DriverManager.getConnection(url,username,password);
			System.out.println("Connected");
			return conn;
		}catch(Exception e){System.out.print(e);}
		
		
		return null;
	}

 

 

 

Spoiler

		database.var1 = 1;
    		database.var2 = "blue";
    		try {
				database.post();
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

 

 

 

 

 

Edited by GPSwap

You should consider using a PHP script for this, 2 reasons, you can modify it outside of the script code without re-compiling the script (Useful for SDN in the future) and secondly you can hide your MySQL credentials :)

If you've tested the code and it works, but doesn't when applied to OSBot, then OSBot's at fault.

Likely, the OSBot's SecurityManager is preventing you from running this. Check the OSBot logger for details; be sure to add logger.error(e) to your exception block, so that any errors that occur are logged out to OSBot's logger.

:edit:

I just spotted a Class.forName(driver); in your code, and I'm almost certain that's blocked in OSBot through my own trial and error.

Edited by liverare

  • Author

dang that sucks, guess I have some more learning to do then ^.^

7 minutes ago, GPSwap said:

dang that sucks, guess I have some more learning to do then ^.^

I've just found this snippet of code from here. Adapt and try it:

String url = "jdbc:mysql://localhost:3306/javabase";
String username = "java";
String password = "password";

System.out.println("Connecting database...");

try (Connection connection = DriverManager.getConnection(url, username, password)) {
    System.out.println("Database connected!");
} catch (SQLException e) {
    throw new IllegalStateException("Cannot connect the database!", e);
}

If this doesn't work, then one option may be to create a PHP/ASP.NET website which handles the server stuff for you when you hit the URL with some URL parameters: http://myawesomebottracker.com/?howmanylogs=10&timeinminutes=2014213213121212

etc.

Edited by liverare

  • Author
28 minutes ago, liverare said:

I've just found this snippet of code from here. Adapt and try it:


String url = "jdbc:mysql://localhost:3306/javabase";
String username = "java";
String password = "password";

System.out.println("Connecting database...");

try (Connection connection = DriverManager.getConnection(url, username, password)) {
    System.out.println("Database connected!");
} catch (SQLException e) {
    throw new IllegalStateException("Cannot connect the database!", e);
}

If this doesn't work, then one option may be to create a PHP/ASP.NET website which handles the server stuff for you when you hit the URL with some URL parameters: http://myawesomebottracker.com/?howmanylogs=10&timeinminutes=2014213213121212

etc.

that snippet says its connecting but wont actually let me interact with the database, I guess im gona have to go the php website route, tyvm for the help

Create an account or sign in to comment

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.