Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

work with a SQL database

Status
Not open for further replies.

cfreak

Programmer
Sep 7, 2003
2
DE
Hello,
can someone tell me how to use a SQL-Database in a java-applet?
 
If you mean an applet running in a browser, that may not be possible. If it is, many security issues exist. The more modern common approach would be to have the applet interface with a web server application. That server application would then have access to the database.

If you just want to know how to access SQL database from Java, see the JDBC tutorials at java.sun.com


-pete
 
I believe (i do it through access how different can it be) you have to set up and ODBC link to the SQL database.
Some sample code below

Now please bear in mind I am a complete novice and teaching myself. But fo Access this works. I have tested it against SQL and it works too when data migration done.

Connection conn;
boolean dbOpen;

openDatabase()
{
int result = 0;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn = DriverManager.getConnection("JDBC:ODBC:newmar","admin","");
}
catch(SQLException ex)
{
System.out.println("excp");
System.out.println ("\n*** SQLException caught ***\n");
while (ex != null)
{
System.out.println ("SQLState: " +
ex.getSQLState ());
System.out.println ("Message: " + ex.getMessage ());
System.out.println ("Vendor: " +
ex.getErrorCode ());
ex = ex.getNextException ();
System.out.println ("");
result++;
}
}
catch(Exception ex)
{
System.out.println(ex);
System.out.println("open Fail");
result++;
}
if (result > 0)
{
dbOpen = false;
}
else
{
dbOpen = true;
}


I am sure you will get the jist. I sort of jigglrd it from sun web site on JDBC pretty good stuff. Tells you how to retrieve and place data. Again I am not a SQL expert and am using simple SQL statements..
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top