Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Problem with Applet and JDBC for SQL server

843854Oct 25 2002 — edited Oct 30 2002
Hi!

I've a problem that is really bugging me.

I'm running an Microsoft SQL-Server 2000 on a win2000 server. On the same server I'm running Microsoft IIS for Web stuff.

I've made one HTML page that calls an applet which in turn are accessing the SQL-database.

The strange thing is that when I'm running the applet and html file locally in Oracle JDeveloper, it is working like a charm, but when I run it in the Webbrowser the connection and reading from the sql-server does not work anymore.

I'm using Microsofts free driver for connecting to SQL server 2000.

I've put the Microsoft jdbcdriver .jar files in a directory on the server, I've added the 3 paths to the 3 jdbcdriver .jarfiles to the servers' CLASSPATH variable.

I've also (ofcourse) put the .class file for my applet (which I call JDBCTest.class) on the server under the subdirectory JDBCTest. I've tried to put the path to the applet .class file in the CLASSPATH but that did not help either.

Below is the two files containing the testcode that does not work (if I can get this testcode to work, then my application I'm developing will work too).

Thank you VERY much for any help I can get on this one.

Best regards

Fredrik
---
This is the directory setup I'm using right now on the server

webservername/wwwroot/Test.htm (applet htm file)
webservername/wwwroot/JDBCTest/JDBCTest.class
webservername/wwwroot/JavaLib/JDBCdriver .jar files
____________________________
html file - Test.htm

<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=windows-1252">
<TITLE>
Title
</TITLE>
</HEAD>
<BODY>
<H2>
This is sample HTML text.
</H2>
<BR>
<APPLET CODE="JDBCTest.JDBCTest.class" HEIGHT="600" WIDTH="600" ALIGN="bottom" VIEWASTEXT>This browser does not appear to support Applets.</APPLET>
</BODY>
</HTML>
______________________

Java applet code - JDBCTest.java (JDBCTest.class compiled)

package JDBCTest;
import java.applet.Applet;
import java.sql.*;
import java.awt.*;

public class JDBCTest extends Applet
{
private java.sql.Connection conn = null;
private String strSQL;

public void init() {

setBackground(Color.blue);
try{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
conn = DriverManager.getConnection("jdbc:microsoft:sqlserver://webservername:1433;User=usr;Password=pwd"); //Instead of webservername, Usr and pwd above I'm using real values
// I don't want to give you the real ones offcourse :o)
}
catch(ClassNotFoundException e){
System.out.println("can't find the JDBCdriver class");
}

catch(Exception e){
System.out.println("Connection error");
e.printStackTrace();
}
getValues();
closeConnection();
}

private void getValues()
{
String strSQL = "select Period from Test";
Statement stmt;
try {
stmt = conn.createStatement();
ResultSet rsResult = stmt.executeQuery(strSQL);

int rowCount = 1;
while (rsResult.next()) {
Label lbl = new Label();
System.out.println("Row " + rowCount + ": ");
System.out.println("Period: " + rsResult.getString("Period"));
lbl.setText(rsResult.getString("Period"));
add(lbl);
}
stmt.close();

} catch(SQLException SQLe) {
System.out.println("SQL statement error: ");
SQLe.printStackTrace();
} catch(Exception e) {
System.out.println("Error in getValues(): ");
e.printStackTrace();
}
}
private void closeConnection(){
try{
if(conn!=null)
conn.close();
conn=null;
}
catch(Exception e){
System.out.println("Could not close connection!");
e.printStackTrace();
}
}
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 27 2002
Added on Oct 25 2002
3 comments
306 views