JDBC connection
with MS SQL Server 2000
I'm trying to connect the MS SQL server 2000 database table through the JSP page. I'm using the local machine. I'm trying with these below line DriverManager.registerDriver(new jdbc.sqlserver.SQLServerDriver());
Plz help me. Ashish Here is a sample code I used to connect from jsp to sqlserver using dsn. Find Helpful
public String setDBConn()throws Exception { String url = "jdbc:odbc:Fred"; Connection con; Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); con = DriverManager.getConnection(url,"", ""); Statement stmt = con.createStatement(); String createTableCoffees = "CREATE TABLE COFFEES " + "(COF_NAME VARCHAR(32), SUP_ID INTEGER, PRICE FLOAT, " + "SALES INTEGER, TOTAL INTEGER)"; stmt.executeUpdate(createTableCoffees); stmt.executeUpdate("INSERT INTO COFFEES " + "VALUES ('Colombian', 101, 7.99, 0, 0)"); stmt.executeUpdate("INSERT INTO COFFEES " + "VALUES ('French_Roast', 49, 8.99, 0, 0)"); String query = "SELECT COF_NAME, PRICE FROM COFFEES"; ResultSet rs = stmt.executeQuery(query); String s1="START ["; while (rs.next()) { s1 += "-" + rs.getString("COF_NAME"); //float n = rs.getFloat("PRICE"); //System.out.println(s1 + " " + n); } return s1; } Pravin Sapkal Do you have a Java Problem?
Java Books
Return to : Java Programming Hints and Tips All the site contents are Copyright © www.erpgreat.com
and the content authors. All rights reserved.
|