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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

my sql data base connection 1

Status
Not open for further replies.

abyinsydney

Programmer
Feb 17, 2004
99
AU
greetings fellow citizens

I'm trying to connect to the database thro jsp to mysql databse with following syntax

Class.forName("org.gjt.mm.mysql.Driver");
conn = DriverManager.getConnection
("jdbc:mysql://168.217.20.68/archiving username="tasol" password="tasol")
Statement stat=conn.createStatement();
ResultSet rc = stat.executeQuery("select * from user_login ");


It is giving me an erro i reckon the error is in the conn statement
what is the correct syntax for username and password to connect to the data bse

Any suggestions would be appreciated

aby
 
conn = DriverManager.getConnection ("jdbc:mysql://host:3306/dbName", "username", "password");

You should also use the new driver class com.mysql.jdbc.Driver
 
greetings sedj
Thanx sedj it seems to work with out the class com.mysql.jdbc.Driver .Programming after a long time hence tends to forget the syntaxs .However can you help me out with an algorith or may be some solution to my problem.


Connection connection = null;
try {
// Load the JDBC driver
Class.forName("com.mysql.jdbc.Driver").newInstance();
// Create a connection to the database
String serverName = "localhost";
String mydatabase = "mydatabase";
String url = "jdbc:mysql://" + serverName + "/" + mydatabase; // a JDBC url
String username = "username";
String password = "password";
connection = DriverManager.getConnection(url, username, password);
} catch (ClassNotFoundException e) {
// Could not find the database driver
} catch (SQLException e) {
// Could not connect to the database
}
I have written this code for database connectivity.I want to put this code in a text file so that my jsp reads it

How do i read the text file or how do my jsp read this text file.The phenemonan(spelling) being that a person is flexible enough to change the server name and database name.with the change of database and server name the jsp should read this file and connect to the corresponding destination.
i reckon it would be text file thro which database connectivity has to be read.

Could you thro some light on it

thanx a lot for your support and please accept my gesture of gratitude TOWARDS A HELPING HAND.

However to be honest came across this code written by venu while answering the queries for other members

aby
 
You could use a properties file and the java.util.Properties object :

The file looks like (for example) :

user=joe
password=me
server=localhost

Then in java :
Code:
Properties props = new Properties();
props.load(new FileInputStream("mydb_props.properties"));
String user = props.getProperty("user");
String password = props.getProperty("password");
 
greetings sedj
your answer is not visible on the screen could you repost it please


aby
 
You could use a properties file and the java.util.Properties object :

The file looks like (for example) :

user=joe
password=me
server=localhost

Then in java :

Properties props = new Properties();
props.load(new FileInputStream("mydb_props.properties"));
String user = props.getProperty("user");
String password = props.getProperty("password");
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top