Rob Bamforth's Blog
Java, SQL, MySQL, Networking, SQL Server, PHP, COM, DBA + ODBC

Jun
04


Data transfer speed table

USB 1.0: > 2 MPPS
USB 2.0 FULL SPEED: 12 MBPS
USB 2.0 HIGH SPEED: 180 MBPS
FIREWIRE-400: 400 MBPS
FIREWIRE-800: 800 MBPS
ENTERNET [10BASE-T]: 10 MBPS
FAST ETHERNET [100BASE-T]: 100 MBPS
GIGABIT ETHERNET [1000BASE-X]: 1000 MBPS
ATA-133: 1064 MBPS
SATA-150: 1200 MBPS





NOTE: these are rough speeds that may be possible.

The typical sustained transfer rate will be lower. Data rate is also dependent on the system architecture, the PCI bus and the attached USB devices

Jun
03


A very simple method to force case sensitivity in a select statement:

SELECT * FROM DBusers WHERE username = ‘AGENT1′ AND password = ‘paSSworD’ COLLATE SQL_Latin1_General_Cp1_CS_AS


The above statement will only return rows where the password value is exactly paSSworD, case specific.


May
05

The xp_cmdshell option is a server configuration option that enables system administrators to control whether the xp_cmdshell extended stored procedure can be executed on a system. By default, the xp_cmdshell option is disabled on new installations and can be enabled by using the Policy-Based Management or by running the sp_configure system stored procedure as shown in the following code example:

– To allow advanced options to be changed.
EXEC sp_configure ’show advanced options’, 1
GO
– To update the currently configured value for advanced options.
RECONFIGURE
GO
– To enable the feature.
EXEC sp_configure ‘xp_cmdshell’, 1
GO
– To update the currently configured value for this feature.
RECONFIGURE
GO

 

The following link illustrates how to use the xp_cmdshell command  to export data from a table in the database to a flat file:

http://robbamforth.wordpress.com/2008/11/03/sql-outout-data-from-sql-server-to-file-bcp/

May
01

 

This example shows how to copy a scheduled backup job from one instance of SQL server 2005 to another.

In Microsoft SQL Server Management Studio, expand the SQL Server Agent tree.

Expand the jobs tree.

Here you will see a list of all the jobs currently stored on the server.

 

Right-click on the job that you want to copy over to a second server.
Select Script Job as –> Create To –> New Query Editor Window.

 

This will open a new window in the management studio containing auto-generated code.

Connect to the Second server, which will be the destination for the copied job.

Open up a new tab in the management studio – Copy the entire auto-generated code from the previous step and paste it into the new tab.

 

Below is the auto-generated code ready to execute on the new server.
Execute the whole code to continue.

 

Refresh and expand the Jobs tab on the second server, all being well the copied job will be displayed in the job list.

 

Right-click the job and select Properties to view the details.

You will see that the steps, schedules, alerts, notifications etc. will have been copied across. The job will now run on server 2 in the same way as it ran on server 1.

Apr
30

 

How to allow SQL server to allow incoming connections

 

Open SQL server service area configuration

 

 

Start à all programs à SQL server 2005 à configuration tools à SQL server service area configuration

 

Select: Surface Area Configuration for Services and Connections.

 

Under the Database Engine tree, select Remote connections.

 

Select Local and remote connections.

 

I use Using both TCP/IP and named pipes, but select the option that fits your requirements.

 

 

Click apply.

 

Next you will need to re-start the Database Engine service.

 

Select the Service option under Database Engine Tree.

 

 

 

 

 

When the service has stopped successfully, slick the Start button to initiate the service.

Apr
27

This example shows how to build up a string to post to a web form, and return the results generated.

Element1 is the first variable the the post accepts – “Value 1″ is the literal string bieng passed to it.
Element2 is the second variable that the post accepts – “Value 2″ is the literal string bieng passed to it.
Element3 is the third variable that the post accepts – “Value 2″ is the literal string bieng passed to it.

http://www.examplewebsite.asp is the web page that the data is bieng posted to.

 

//Create Post String
String data = URLEncoder.encode(“Element1″, “UTF-8″) + “=” + URLEncoder.encode(“Value 1″, “UTF-8″);
data += “&” + URLEncoder.encode(“Element2″, “UTF-8″) + “=” + URLEncoder.encode(“Value 2″, “UTF-8″);
data += “&” + URLEncoder.encode(“Element3″, “UTF-8″) + “=” + URLEncoder.encode(“Value 3″, “UTF-8″);
                
         
// Send Data To Page
URL url = new URL(“http://www.examplewebsite.asp”);
URLConnection conn = url.openConnection();
conn.setDoOutput(true);
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
wr.write(data);
wr.flush();
   
// Get The Response
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line;
while ((line = rd.readLine()) != null) {
        System.out.println(line);
        //you Can Break The String Down Here
}

 

You can manipulate the line variable to read in the information returned from the post.

Apr
27

Here is a very simple script to return model and serial number information for your computer.

To retrieve serial number of the computer run the following command from command line

wmic bios get serialnumber

To retrieve model name of the computer run the following command from command line

wmic csproduct get name

This code doesn’t return information for all computers, but I’ve found it very usefull where its available.

Apr
01

You can force the JTextArea (text area) to scroll to the bottom by moving the caret to the end of the text area after the call to append:

textarea.append(“Some Text\n”);
textarea.setCaretPosition(textarea.getDocument().getLength()); 

Mar
30

How to remeve a row from a JTable.

This example illustrates how to remove a row from an existing JTable called table.
The row to be deleted will be the row that has been selected by clicking the mouse on it.

 

//CREATE MODEL INSTANCE FROM EXISTING TABLE
DefaultTableModel model = new DefaultTableModel();
model = (DefaultTableModel) table.getModel();

//DELETE THE SELECTED ROW
model.removeRow(table.getSelectedRow());
                
//INSERT A NEW EMPTY ROW
model.addRow(new Object[]{“”,”",”"});

 

I used this with a confimation dialog, asking the user to confirm this is the correct row to be deleted;

int n = JOptionPane.showConfirmDialog(

null,

                “Are you sure you want delete – ” + table.getValueAt(table.getSelectedRow(), 2) + “?”,

                “”,

                JOptionPane.YES_NO_CANCEL_OPTION);          

           

//the user has clicked the cross

if(n == -1)

{

   return;

}

           

//the user has clicked cancel

if(n == 2)

{

   return;

}

 

//yes

if(n == 0){

   

    //CREATE MODEL INSTANCE FROM EXISTING TABLE

    DefaultTableModel model = new DefaultTableModel();

    model = (DefaultTableModel) table.getModel();

 

    //DELETE THE SELECTED ROW

    model.removeRow(table.getSelectedRow());

               

    //INSERT A NEW EMPTY ROW

    model.addRow(new Object[]{“”,”",”"});

}

           

//no

if(n == 1){

    return;

}

Mar
24

How to view line numbers in SQL 2005 management studio.

YES it is possible and very simple to switch on.

From the main menu bar go to;

Tools –> Options;
Select/Expand the Text Editor tree;
Select the All Languages tree;
Under the Display header, check the Line Numbers box.

Click the OK button and line numbers will immediately be shown on the left of the T-SQL window.