---restore content starts---
JSP connection database is divided into: Jdbc-odbc Bridge, database driver Connection (Novice Note, if there is an error please God pointed out).
Bridging mode:
To connect to an Access database:
First, in access to establish a database, input good data (ok seemingly this is nonsense), tick the location of the database, then the data source configuration, open Control Panel, administrative tools, such as ODBC data source, add, select the driver for access, Typically Microsoft Access Driver (*.mdb Newer version will also have one more *.accdb), complete with the ODBC Microsoft Access installation now a data source name in the data source name, where Mas is used as the As the data source name, and then click Select in the Database bar, choose the database you just created, and complete the data source configuration at this time
The following database is connected in the program: the database name used here student table name tb_a data Source name MAS database username user password password;
Try{Connection conn; Statement Stat; ResultSet rs;//Load DriverClass.forName ("Sun.jdbc.odbc.JdbcOdbcDriver");//connecting to a databaseconn = Drivermanager.getconnection ("Jdbc:odbc:mas", "User", "password");//call the Createstatement method to create the Conn objectStat = Conn.createstatement (intTypeintconcurrency);//Query StatementsString Sele = "SELECT * FROM Tb_a";//Execute Queryrs =stat.executequery (Sele);//Output Database content (take three fields as an example) while(Rs.next ()) {Out.print (rs.getstring (1)); Out.print (Rs.getfloat ("Float")); Out.print (Rs.getdata ("Data"));}}Catch(/*ClassNotFound*/Exception e) {}
The Jdbc-odbc Bridge Access database is now complete!
To connect to the SQL Server database:
Configure the data source to match earlier in Access until you select the driver, select Sqlsever, write the data source name in the settings panel Select Server, select Use user input login ID and password verification, enter ID and password, select change default database- > select the database you want to connect to complete.
To run the code is to prompt 1433 port error, you need to find the SQL Server Configuration tool, SQL Server network configuration, MSSQLSERVER protocol, find the TCP/IP right-click Properties, pull the TCP port at the end of the address, 1433 save, Right-click TCP/IP to start, and then
The Code section is the same as access.
Drive Connection mode:
No need to configure a data source
Sql server
Download a SQL Server database driver on the Internet and put it in Web-inf Lib;
connection Conn; Statement Stat; ResultSet rs; try { load driver class.forname ("Com.microsoft.sqlserver.jdbc.SQLServerDriver" );} catch (Exception e) {} try {String u = "jdbc:sqlserver://localhost:1433 databasename=student" ; Conn =drivermanager.gerconnection (U, "user", "password" ); Stat =conn.createstatement (); String Sele = "SELECT * from Tb_a" =stat.executequery (Sele);
while (Rs.next ()) {
Out.print (rs.getstring (1));}
}catch (Exception e) {}
Connect to the Oracle database download driver;
Classes12.zip copied to Lib (same as Sqlsever) in Oracle/ora81/jdbc after the installation completes Oracle
Connection Conn; Statement State; ResultSet rs;
Try{class.forname ("Oracle.jdbc.driver.OracleDriver");
}catch (Exception e) {}
try{string s= "Jdbc:oracle:then: @localhost: 1521:user"; conn=drivermanager.getconnection (S, "User", " Password "); String Sele= "SELECT * from Tb_a"; stat=conn.createstatement ();
Rs=stat.createquery (Sele);
Wile (Rs.next ()) {
Out.print (rs.getstring (1));
}
}catch (Exception e) {}
Several ways to connect a database with JSP