Results 1 to 7 of 7
Thread: Connect Java to SQL
- 12-21-2010, 08:31 AM #1
Member
- Join Date
- Jan 2010
- Posts
- 80
- Rep Power
- 0
Connect Java to SQL
Hi
I'm working these days on how to connect java applet with SQL database.
I have searched many times and finally found this code
Java Code:import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import java.sql.Statement; public class Main { public static void main(String[] args) throws Exception { if (conn != null) { System.out.println("Connection attempt was successful!"); try { conn.close(); } catch (SQLException ex) { ex.printStackTrace(); System.out.println("Problem closing the connection"); } } } static Connection conn; static Statement st; static { try { // Step 1: Load the JDBC driver. Class.forName("org.hsqldb.jdbcDriver"); System.out.println("Driver Loaded."); // Step 2: Establish the connection to the database. String url = "jdbc:hsqldb:data/tutorial"; conn = DriverManager.getConnection(url, "sa", ""); System.out.println("Got Connection."); st = conn.createStatement(); } catch (Exception e) { System.err.println("Got an exception! "); e.printStackTrace(); System.exit(0); } } }
Java Code:// Step 1: Load the JDBC driver. Class.forName("org.hsqldb.jdbcDriver");
Java Code:// Step 2: Establish the connection to the database. String url = "jdbc:hsqldb:data/tutorial";
I'll be thankful to you guys.
:)
- 12-21-2010, 08:55 AM #2
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,568
- Rep Power
- 15
They are explained in the Tutorial. Go through that from front to back.
- 12-22-2010, 07:10 AM #3
Member
- Join Date
- Nov 2010
- Location
- New Delhi
- Posts
- 50
- Rep Power
- 0
Class.forName("org.hsqldb.jdbcDriver");
loads the database drivers that will provide the necessary things i.e. connectivity to a specific data base u r using for ur application.
String url = "jdbc:hsqldb:data/tutorial";
this is the url for the data base server.
if ur database is on the same machine then u can change it
(MS-Access database)
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:FMSDB",null ,null);
//FMSDB is database name and first null is username and second is password
for more details u can visit
http://java-sql.blogspot.com/2011/03...ns-injava.htmlLast edited by baloda; 03-28-2011 at 12:24 PM.
- 12-24-2010, 01:12 AM #4
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,568
- Rep Power
- 15
- 12-24-2010, 06:24 AM #5
Member
- Join Date
- Nov 2010
- Location
- New Delhi
- Posts
- 50
- Rep Power
- 0
i think that will be easy to understand for a starter.
http://java-sql.blogspot.com/2011/03...ns-injava.htmlLast edited by baloda; 03-28-2011 at 12:25 PM.
- 12-30-2010, 07:43 PM #6
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,568
- Rep Power
- 15
- 12-31-2010, 12:16 PM #7
Member
- Join Date
- Nov 2010
- Location
- New Delhi
- Posts
- 50
- Rep Power
- 0
May be, u r right. but at that time i thought like that.
http://java-sql.blogspot.com/2011/03...ns-injava.htmlLast edited by baloda; 03-28-2011 at 12:26 PM.
Similar Threads
-
connect to oracle from java
By ahmadian in forum Advanced JavaReplies: 7Last Post: 05-15-2013, 05:15 PM -
how to connect java to mysql?
By ranvir in forum JDBCReplies: 2Last Post: 12-11-2010, 09:34 AM -
how to connect 2 java files
By McArthurG in forum New To JavaReplies: 3Last Post: 07-07-2010, 03:34 PM -
connect to web server from mobile using java app.
By jankrishnan in forum Advanced JavaReplies: 1Last Post: 07-15-2008, 05:12 PM -
Making connect 4 in java
By zoe in forum New To JavaReplies: 1Last Post: 08-07-2007, 07:10 AM
Bookmarks