[ start | index | login ]
start > jdbc_grep.py

jdbc_grep.py

Created by admin. Last edited by admin, one year and 291 days ago. Viewed 682 times. #4
[diff] [history] [edit] [rdf]
labels
attachments
jdbc_grep.py (2072)
This is a >>Jython script so you will need to download it before you can run this script.

from java.lang import *
from java.sql import *

# PARAMETERS YOU SHOULD SET ( search for '_here' to see ones u HAVE to set) driver = 'com.mysql.jdbc.Driver' url = 'jdbc:mysql://localhost:3306/your_dbname_here' user = 'db_username_here' pwd = 'db_password_here' catalog = 'name_here' # set this to None to search across all catalogs query = "select count(*) from ? where lower(?) like '%searh_string_here%'" skipSize = 1000

# START of the script Class.forName( driver) conn = DriverManager.getConnection( url, user, pwd) meta = conn.getMetaData()

# fetch and store table names from the catalog tables = meta.getTables( catalog, None, None, None) tableNames = [] while tables.next(): tableNames.append( tables.getString(3))

# in each table for table in tableNames: # check total rows in the table count = 0 stmt = conn.createStatement() query = 'select count(*) from ' + table rs = stmt.executeQuery( query) rs.next() count = rs.getInt(1) rs.close() stmt.close() # check count if count > 1000: print 'SKIPPING', table else: print 'CHECKING', table # fetch all columns cols = meta.getColumns( catalog, None, table, None) while cols.next(): # look for a string column type = cols.getInt(5) if type == Types.CHAR or type == Types.VARCHAR: colName = cols.getString(4) #ps = conn.prepareStatement( query) #ps.setString( 1, table) #ps.setString( 2, colName) #rs = ps.executeQuery() stmt = conn.createStatement() query = "select count(*) from " + table + " where lower( " + colName + ") like '%search_string_here%'" rs = stmt.executeQuery( query) if rs.next(): count = rs.getInt(1) if count > 0: print table, '->', colName, ':', rs.getInt(1) rs.close() #ps.close() stmt.close()

conn.close()

no comments | post comment

Main Menu

  1. Daily Stuff
  2. Hacking
  3. Fun Stuff
  4. Contact Me
  5. >>Nimsoft.biz
  6. >>Seattle Traffic on your cell
December 2008
SunMonTueWedThuFriSat
123456
78910111213
14151617181920
21222324252627
28293031

>>Java RSS Feeds
>>PopURLS

XHTML 1.0 validated
CSS validated
RSS 2.0 validated
RSS Feed

Powered by SnipSnap 1.0b2-uttoxeter

Describe here what your SnipSnap is about!

Configure this box!

  1. Login in
  2. Click here: snipsnap-portlet-2
  3. Edit this box
snipsnap.org | Copyright 2000-2002 Matthias L. Jugel and Stephan J. Schmidt