Total members 11890 |It is currently Thu Apr 25, 2024 7:23 am Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





hai
i like to get code for making adding deleting navigating to database using javaide




Author:

Code:

import java
.sql.*;

public 
Connection openConnection() {
  
Properties properties = new Properties();
  
properties.put("user", ...);
  
properties.put("password", ...);
  
properties.put("characterEncoding""ISO-8859-1");
  
properties.put("useUnicode""true");
  
String url "jdbc:mysql://hostname/database";

  Class.
forName("com.mysql.jdbc.Driver").newInstance();
  
Connection c DriverManager.getConnection(urlproperties);
  return 
c;
}
 


To create connection and statement :
Code:
Connection c = createConnection();
Statement st = c.createStatement();

To run SQL
Code:

int id 
1//Any value
String sql "SELECT Name FROM students WHERE Id = " id;
ResultSet rs st.executeQuery(sql);
 


to show results
Code:
ResultSet rs = st.getResultSet();
try {
  while (rs.next()) {
    int id = rs.getInt(1);
    String userName = rs.getString(2);
    String firstName = rs.getString(3);
    String surname = rs.getString(4);
    Timestamp timeReg = rs.getTimestamp(5);
     
  }
} finally {
  rs.close();
}







for net-beans
Code:
http://netbeans.org/kb/docs/ide/java-db.html


_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time
Post new topic Reply to topic  [ 2 posts ] 

  Related Posts  to : navigating to database using java
 Java Library Database Management System Project     -  
 2 different database     -  
 Selecting a Database in php     -  
 information about database     -  
 database connection     -  
 List all database in php     -  
 Login using jsp,Servlets and Database following MVC     -  
 Persist in DataBase with AspectJ (AOP)     -  
 dump Mysql database     -  
 import Mysql database     -  



cron





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com