Click to See Complete Forum and Search --> : Applet not connecting DB ???


simba
October 5th, 1999, 03:36 PM
Hi i am trying to connect MS SQL Server dB on NT server from Win 95 machine using Applet. When i run the AppletViewer, it goes into the exception. I cannot use the JDBCODBC bridge driver. I downloaded the TdsDriver of inetsoftwar.de. It works great for an application, but when it comes to an applet, it falls into the exception. Given below is the java code. Please reply asap.


import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
import java.util.*;
import java.io.*;
import java.applet.*;


public class frontend1 extends JApplet {

Connection con;
Statement stmt;
ResultSet rs;

GridBagLayout gridBagLayout1 = new GridBagLayout();
JTextField jTextField1 = new JTextField();
JTextField jTextField2 = new JTextField();
JTextField jTextField3 = new JTextField();
JTextField jTextField4 = new JTextField();
JTextField jTextField5 = new JTextField();
JButton jButton1 = new JButton();
JButton jButton2 = new JButton();

//Construct the frame
public void init() {

try {
jbInit();
//jdbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}

//Component initialization
private void jbInit() throws Exception {

this.getContentPane().setLayout(gridBagLayout1);
this.setSize(new Dimension(400, 300));

jButton1.setText("Records");
jButton1.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(ActionEvent e) {
jButton1_actionPerformed(e);
}
});

jButton2.setText("Servlet");
jButton2.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(ActionEvent e) {
jButton2_actionPerformed(e);
}
});

this.getContentPane().add(jTextField1, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
,GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(11, 12, 3, 0), 80, 6));
this.getContentPane().add(jTextField4, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0
,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(19, 20, 21, 0), 80, 6));
this.getContentPane().add(jTextField5, new GridBagConstraints(2, 1, 1, 1, 0.0, 0.0
,GridBagConstraints.SOUTH, GridBagConstraints.NONE, new Insets(1, 0, 19, 20), 80, 6));
this.getContentPane().add(jTextField2, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0
,GridBagConstraints.NORTH, GridBagConstraints.NONE, new Insets(9, 19, 11, 21), 80, 6));
this.getContentPane().add(jTextField3, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0
,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(11, 5, 9, 15), 80, 6));
this.getContentPane().add(jButton1, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0
,GridBagConstraints.SOUTHEAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
this.getContentPane().add(jButton2, new GridBagConstraints(2, 2, 1, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));



try {

System.out.println("Beginning to Load Driver");
Class.forName("com.inet.tds.TdsDriver");


}
catch(Exception e1) {
System.out.println("Error 1 - " + e1.getMessage());
}

try {

System.out.println("Beginning to Connect DB");
String url = "jdbc:inetdae:servthr11:1433?database=data3";
String login = "admin";
String pas = "web";

con = DriverManager.getConnection(url,login,pas);

}
catch(Exception e2) {
System.out.println("Error 2 - " + e2.getMessage());
}


}

void jButton1_actionPerformed(ActionEvent e) {

try {

stmt = con.createStatement();

rs = stmt.executeQuery("select workcity from address_d where id ="+"'"+100326801+"'");

while(rs.next()) {

System.out.println(rs.getString(1));

jTextField1.setText(rs.getString(1));

}
}
catch(Exception e3) {
System.out.println("Error 3 - " + e3.getMessage());
}


}

void jButton2_actionPerformed(ActionEvent e) {

}


}