Create jdbc odbc database
hi, i want to make a program that uses database, the problem is that i cant find a moveable database that i can transfer with my program. for example i have a jar file that use microsoft access as a database, but when i want to copy those two files to another computer i have to redefine the setting that allows access to be used as a odbc database. if some know a database the can be move from one computer to another without any changes needed please help me.
shuky.
shuky19 wrote:
hi, i think you didnt understand my problem, I think I understand your problem - you don't understand my solution.
i used access because it is a database that comes with one file, i can copy my jar file and the access file and thats it, with other database i dont even know where the database is? Yes you do - it's in the JAR or WAR or EAR file that you deploy.
i dont want to install mysql in a client computer, i want it to be a small software, my database dont need to include a large amount of information.In-memory for an individual would be sufficient, right? You don't envision more than one user for the database, correct? Or is the database deployed as a server?
any ideas?Yes, Derby or Hypersonic.
%
Similar Messages
-
someone please help me with this issue. i wonder why i need to put 2 lines of executeUpdate() to successfully insert a new record... thanks in advance for those who helped ;)
peixing.
import java.io.*;
public class Index{
public static void main(String[] args)throws IOException{
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
String userId = "";
System.out.println("Welcome to New World Inc.");
System.out.println("1. Create new user");
int choice = 0;
do{
System.out.print("Please select an option: ");
try{
choice = Integer.parseInt(input.readLine());
catch(NumberFormatException e){
//e.printStackTrace();
choice = 0;
}while(choice<1 || choice>3);
if(choice==1){
Account acc = new Account();
do{
System.out.print("Enter user name: ");
try{
userId = input.readLine();
acc.setUserId(userId);
catch(Exception e){
e.printStackTrace();
}while(userId.equals(""));
import java.sql.*;
public class Account{
DBC dbc;
public Account(){
dbc = new DBC();
dbc.setUp("database");
public void setUserId(String userId){
int status = dbc.updateRequest("INSERT INTO Account VALUES('" + userId + "','','')");
dbc.updateRequest("INSERT INTO Account VALUES('" + userId + "','','')");
//<===== i wonder why i need to write an additional updateRequest then i am able to insert a new record into my database....
//its so weird. and everytime i take away this additional method, i cannot add a new record into my database
import java.sql.*;
public class DBC{
private Connection con;
public void setUp(String dsn){
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
catch(Exception e){
System.out.println("Load driver error");
try{
String s = "jdbc:odbc:" + dsn;
con = DriverManager.getConnection(s, "", "");
catch(Exception e){
e.printStackTrace();
public int updateRequest(String dbQuery){
int count=0;
try{
Statement stmt = con.createStatement();
stmt.executeUpdate(dbQuery);
count = 1;
catch(Exception e){
count = -1;
return count;
}DrClap, are you able to give me a solution as to how can i commit the update or close the connection ? however i notice something you might have "mistakened"
its not that i can't create a new record into my database... when i only put a single executeUpdate(), the new record is not created, but when i put 2 lines of executeUpdate() then the new record is reflected in the database...
hope you may give me some code samples to clarify my doubts to this issue.
thanks in advance
peixing. -
How to create db conn for JDBC-ODBC Bridge for MS Access in ADF APP?
Sir,
How to create db conn for JDBC-ODBC Bridge for MS Access in ADF APP?
RegardsHello Every Body!
I succeeded in getting connect to the ms access database in adf application in jdeveloper as below:
First in control panel to to admin tools and go to data source(odbc) and create system dsn as bellow pic
Then go to jdeveloper resources ide conn and then database and new database conn and then select jdbc-odbc briddge and then give custom jdbc url as bellow pic
Cheers
tanvir -
Remote Database connection throught JDBC-ODBC
Hi everybody
I've developed an application which connects to a MS Access database throught the JDBC-ODBC bridge; if the database is on my local machine I've no problem at all, but I now need to connect to a database on a remote PC. I've set the DSN entry for the database on the remote computer and try to connect using something like:
String db_name="jdbc:odbc:remote_pc_name\\\\DSN_db_name";
Properties db_prop=new Properties();
db_prop.setProperty("user","username");
db_prop.setProperty("password","user_password");
Connection dbconn=DriverManager.getConnection(db_name,db_prop);
but the ODBC driver gives me the message
"[Microsoft][ODBC Driver Manager] DSN not found and driver not specified.
I've tried other possible "connection strings" but I always get the same message.
The software works properly if I connect to the local DB with:
String db_name="jdbc:odbc:DSN_db_name";
Any idea how to connect to a remote DB through ODBC?
ThanksNo need for a separate thread really is there? its still relevant to the original.
import java.awt.*;
import java.sql.*;
public class JDBC1 extends Frame {
private static final String DB = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=\\\\http:\\\\www.cs.stir.ac.uk\\~dcl\\databasename.mdb";
public static void main(String[] arguments) {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
System.out.println("Driver registered!");
Connection conn = DriverManager.getConnection(DB, "", "");
System.out.println("Connected!");
Statement st = conn.createStatement();
System.out.println("Statement created!");
ResultSet rec = st.executeQuery("SELECT * FROM people");
System.out.println("Queried!");
while( rec.next() ) {
System.out.println( rec.getString(2) );
st.close(); //close the statement
conn.close(); //close the connection
catch( SQLException s ) {
System.out.println("SQL Error: "+ s.toString() + " " + s.getErrorCode() );
s.printStackTrace();
catch( Exception e ) {
System.out.println("Error: "+ e.toString() + e.getMessage() );
} -
JDBC-ODBC bridge for MSSQL database
Hi,
I have SAP 2 MSSQL synchronous scenario and I need to select data from MS SQL 2005 database located on the remote system via XI 3.0. The database provides only ODBC access. I am using JDBC receiver and I would like to use sun.jdbc.odbc.JdbcOdbcDriver as a driver. I searched this forum, but the most of threads describe, how to connect to MS Access database, which is not my case. I used XI JDBC/FTP connection Test and XML Validation Application described in SAP Note 1085539 to test it. I used the following settings:
Driver Class (fully qualified) sun.jdbc.odbc.JdbcOdbcDriver
JDBC URL jdbc:odbc:Driver://<host IP>;databaseName=<name>
User Name my username
Password my password
I got the following error:
Exception Occurred : [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
Exception Stack Trace : java.sql.SQLException: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6958)
at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7115)
My questions are: Is it possible to use sun.jdbc.odbc.JdbcOdbcDriver in this scenario? If so, what should I put as JDBC URL? Do I need to create DSN on the XI system? (it is a Windows NT based machine).
Thanks a lot for your answers.Have you already deployed the drivers (msbase.jar, mssqlserver.jar, msutil.jar) ??
If so,
The JDBC drivers should be:
com.microsoft.jdbc.sqlserver.SQLServerDriver
And the connection should be:
jdbc:microsoft:sqlserver://hostname:1433;DatabaseName=name
else
For the drivers:
http://developers.sun.com/product/jdbc/drivers -
Access database/ java application/ jdbc odbc
i am building an access database with a java application and get the following error message when i try to run the application. the log in window that i have does not have a password text field, only a field for the odbc name.
java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Not a valid password.
at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6106)
at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:6263)
at sun.jdbc.odbc.JdbcOdbc.SQLDriverConnect(JdbcOdbc.java:2488)
at sun.jdbc.odbc.JdbcOdbcConnection.initialize(JdbcOdbcConnection.java:317)
at sun.jdbc.odbc.JdbcOdbcDriver.connect(JdbcOdbcDriver.java:160)User/password are usually necessary to set up the ODBC source. So you may need find out who set up your ODBC source. Or you need find the correct user/password and reset the ODBC source.
PC -
JDBC-ODBC-Bridge connection to SQL Database
Hi guys
I have a problem. I've made a little game which I want to put on my website. It has a highscore-list which I want to connect to my web host's database server to get the current list.
I tried this with JDBC and got it to work locally but when I uploaded it to my site it didn't work. I contacted my web host's technical support who told me that their server didn't have the JDBC driver and that I should use ODBC instead. I did lots of reading and found out about this JDBC-ODBC-Bridge. I have since been trying to implement this into my program but hasn't been successful.
In my original JDBC connection I used
private String url = "jdbc:mysql://" + host + "/" + mydatabase;
Class.forName("com.mysql.jdbc.Driver");
Connection connection = DriverManager.getConnection(url, username, password);Now I'm trying
private String url = "jdbc:odbc://" + host + "/" + database;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection connection = DriverManager.getConnection(url, username, password);But, at least when trying it locally, I get the error
java.sql.SQLException: [Microsoft][ODBC Driver Manager] Data source name is too long.
at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6957)
at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7114)
at sun.jdbc.odbc.JdbcOdbc.SQLDriverConnect(JdbcOdbc.java:3073)
at sun.jdbc.odbc.JdbcOdbcConnection.initialize(JdbcOdbcConnection.java:323)
at sun.jdbc.odbc.JdbcOdbcDriver.connect(JdbcOdbcDriver.java:174)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at HighscoreDB.readFile(HighscoreDB.java:53)
at HighscoreDB.displayList(HighscoreDB.java:97)
at HighscoreDB.main(HighscoreDB.java:33)Please help ;)
Edited by: YZF-R1 on 2009-apr-09 13:26YZF-R1 wrote:
masijade. wrote:
Do you know what ODBC is?I think I at least have the basic idea, I learnt most of what I know from this post:
[http://forums.sun.com/thread.jspa?threadID=211735&start=2&forumID=48]
masijade. wrote:
While "reading about this JDBC-ODBC Driver" did you also read about how to enter the URLs for it?No, I couldn't find that piece of information, why don't you tell me ;)
Here
>
masijade. wrote:
Did also read about the fact about needing to configure ODBC DSNs? Or about the fact that the connection URL is radically different if you don't configure one?No I did not. Please explain =)
Here
>
PhHein wrote:
Plus, JDBC-ODBC Bridges are evil!I'm beginning to realize this myself :O:(
BalusC wrote:
Drop that whole ODBC idea and just gently read the documentation which come along with the MySQL JDBC driver.I read a lot of it when I used the JDBC driver locally but how's that going to help me if the server doesn't have the JDBC driver installed?How will the Bridge help you if the ODBC Driver is not installed? And, the JDBC Driver (the Type 4.0 ones, which the MySQL Driver is) is 100% Java, so it can even be included in an Applet, if the HTML page that accesses it is done right, and the jars are "packaged" properly. -
To run a report from command line, when using jdbc-odbc bridge
Hi,
How to run a report from command line, when using jdbc-odbc bridge?
Usually with tns, we do by "rwrun module=<> userid=<user>/<passwd>@tns".
with odbc, we do by "rwrun module=<> userid=<user>/<passwd>@odbc:DSN"
Please specify, what is command line arguments for jdbc-odbc bridge driver?
Environment : Oracle 9i Report Builder on WinNT
Database : Sybase
Regards,
RamananHello Ramanan,
Report Builder : connect JDBC Query in Report Builder is to through Connection Dialog in JDBC Query Editor. User can use a Sign on parameter (can use, default : P_JDBCPDS or can create new) to connect to JDBC Data Source. Connection once made will be mentioned and will be reused through out Reports Builder.
JDBC PDS allows user to connect one or more same or different kind of databases.
While running report through runtime or Server, user can pass the sign on parameter(connection string) value, like any other user parameter.
Syntax for connection string : <username>/<password>@databaseURL . The syntax of database part of connection string depend on the type of JDBC Driver used to connect to Data Source while designing the JDBC Query. databaseURL refer to the location of the database and its format depend on the JDBCPDS river selected in design time while creating the JDBC Query.
rwrun eg :
rwrun report=jdbc_odbc.rdf destype=file desname=output.html desformat=html P_JDBCPDS=scott/tiger@database
Server eg :
http://server.com:8888/servlet/RWServlet?server=MyReportServer+report=jdbc_odbc.rdf+destype=cache+desformat=html+P_JDBCPDS=scott/tiger@database
http :
Please see ORACLE_HOME/reports/conf/jdbcpds.conf for more information.
With Regards
Reports Team -
Problem: connect DB with Applet by JDBC-ODBC bridge
Dear all,
When I connect local MS SQL server by "sun.jdbc.odbc.JdbcOdbcDriver" as below, it works well! However, when I put the similar code under Java Applet program, it cannot run by showing error:
java.security.AccessControlException: access denied (java.lang.RuntimePermission accessClassInPackage.sun.jdbc.odbc)
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:272)
at java.security.AccessController.checkPermission(AccessController.java:399)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:545)
at java.lang.SecurityManager.checkPackageAccess(SecurityManager.java:1501)
at sun.applet.AppletSecurity.checkPackageAccess(AppletSecurity.java:169)
I think Java Applet has some security policy when I try to use applet to connect(read/write) DB. How can I solve it so that I can browse my applet under IE.
Thanks a lot!
Here is my worked code in Java program but not in Applet:
import java.sql.*;
public class TestJDBC1 {
public static void main(String args[]) throws Exception {
String userid = "";
String password = "";
// Register the driver with DriverManager
new sun.jdbc.odbc.JdbcOdbcDriver();
// Get a connection
Connection conn = DriverManager.getConnection("jdbc:odbc:rdr",
userid, password);
// Create a statement for executing SQL
Statement stmt = conn.createStatement();
// Execute a query / SELECT statement
ResultSet rset = stmt.executeQuery("SELECT * FROM PlatformNode");
ResultSetMetaData rsmd = rset.getMetaData();
// Find out how many columns were returned by the query
int count = rsmd.getColumnCount();
// Loop until all rows have been processed
while (rset.next()) {
// Loop until all columns in current row have been processed
for (int i = 1; i <= count; i++) {
// Print out the current value
System.out.print(rset.getObject(i));
// Put a comma between each value
if (i < count) {
System.out.println(",");
// Start the next row's values on a new line
System.out.println("");
// Close the database objects
rset.close();
stmt.close();
conn.close();Hi,
Applets by default are restricted from accessing a lot of things.to enable applest from accessing database and other thngs u need to edit the policy file
Try this.
go to the jre/bin directory open the policytool.exe file
and add permission(in ur case RuntimePermission to access class in package sun.jdbc.odbc) and save the file.
this will enable applets from accessing the databse.
Hope that helps
Note:
policytool.exe must be used to open the java.policy file present in /jre/lib/security directory and then add the permissions
regards,
Partha -
Ms Access problems with Jdbc Odbc!!!
Hi again people,
Im creating a GUI swing project connecting a database (MsAccess) to a dialog using the bridge driver,
The GUI is coming up but im getting runtime errors and the data does not go to the fields, the dialog and connection are in two files:
import java.awt.*;
import java.awt.event.*;
import java.sql.*; //SQL package for the statements
import javax.swing.*;
class DatabaseMan
public ResultSet m_resultSet; //recordset resulting from SQL query
public ResultSetMetaData m_rsmd; //used to get general info about the columns
private int m_nNumberOfFields; //number of fields in a recordset
private Connection conn;
private Statement stmt;
public DatabaseMan(String strSQLQuery)
try
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
try //establish connection to the database
//try to get connection to the database
conn = DriverManager.getConnection("jdbc:odbc:db1");
//this is not where we update the database so we make it read only
stmt = conn.createStatement( ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
m_resultSet = stmt.executeQuery(strSQLQuery);
catch(SQLException exSQL)
System.err.println("\n\n\t\t ***SQLException has" +
"been caught ***\n\n");
while ( exSQL != null)
System.err.println("\nSQLState : " + exSQL.getSQLState() );
System.err.println("\nMessage : " + exSQL.getMessage() );
System.err.println("\nVendor code : "+ exSQL.getErrorCode() );
System.err.println("\n");
exSQL = exSQL.getNextException();
catch( ClassNotFoundException e)
System.err.print("\n\n\tClassNotFoundException has"
+" been caught");
System.err.println( e.getMessage());
catch( java.lang.Exception ex )
ex.printStackTrace();
public void CloseConnection() //close connection to database
try
conn.close();
stmt.close();
m_resultSet.close(); //release the resources
catch (SQLException exSQL )
System.out.println("SQL Exception: " + exSQL.getMessage());
exSQL.printStackTrace(System.out);
public int getNoFields()
return m_nNumberOfFields;
} //end of DatabaseMan.java
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import DatabaseMan;
import javax.swing.*;
class DBviewer extends JDialog implements ActionListener
//JButtons to create toolbar
private JButton m_buttonFirst;
private JButton m_buttonNext;
private JButton m_buttonPrevious;
private JButton m_buttonLast;
private JButton m_buttonClose;
private JButton m_mainbuttonClose;
//textfields to transfer the data from database
private JTextField m_name;
private JTextField m_age;
private JTextField m_weight;
private JTextField m_professionalism;
private JTextField m_speed;
private JTextField m_acceleration;
private JTextField m_jump;
private JTextField m_stamina;
private JTextField m_bravery;
private JTextField m_fitness;
private JTextField m_experience;
//labels to identify the textfields
private JLabel m_labelname;
private JLabel m_labelage;
private JLabel m_labelweight;
private JLabel m_labelspeed;
private JLabel m_labelacceleration;
private JLabel m_labelprofessionalism;
private JLabel m_labeljump;
private JLabel m_labelstamina;
private JLabel m_labelbravery;
private JLabel m_labelfitness;
private JLabel m_labelexperience;
DatabaseMan m_DatabaseMan;
private String strSQLQuery1;
private String type1 = new String("");
public DBviewer(Frame parent, String caption, boolean bModal, String type)
super(parent,caption,true);
setSize(600,400);
setLocation( new Point(150 , 150 )); //position it pops up on screen.
setResizable(false);
strSQLQuery1 = new String("");
type1 = type;
//SQL query to show the horse database
if(type =="Horse")
strSQLQuery1 ="SELECT *" +
"FROM HORSE";
buildHorseGUI();
if(type =="Jockey")
strSQLQuery1 ="SELECT *" +
"FROM JOCKEY"+
" ORDER BY NAME";
buildJockeyGUI();
if(type =="Course")
strSQLQuery1 ="SELECT *" +
"FROM RACECOURSE"+
" ORDER BY NAME";
buildCourseGUI();
m_DatabaseMan = new DatabaseMan(strSQLQuery1);
/*try
{//reset values with default move up to top later
if(m_DatabaseMan.m_resultSet.first())
transferData(type1);
catch( SQLException exSQL)
System.out.println("SQL Exception: " + exSQL.getMessage());
exSQL.printStackTrace(System.out);
public void buildHorseGUI() //construct the horse GUI
buildDefaultGUI(); //build default buttons and toolbar
m_labelname = new JLabel(" Horse Name:",JLabel.CENTER);
m_labelname.setBackground(Color.blue);
m_labelname.setForeground(Color.white);
m_labelage = new JLabel("Age: ",JLabel.CENTER);
m_labelage.setBackground(Color.blue);
m_labelage.setForeground(Color.white);
m_labelweight = new JLabel("Weight(p): ",JLabel.CENTER);
m_labelweight.setBackground(Color.blue);
m_labelweight.setForeground(Color.white);
m_labelspeed = new JLabel("Speed:",JLabel.CENTER);
m_labelspeed.setBackground(Color.blue);
m_labelspeed.setForeground(Color.white);
m_labelacceleration = new JLabel("Acceleration:",JLabel.CENTER);
m_labelacceleration.setBackground(Color.blue);
m_labelacceleration.setForeground(Color.white);
m_labelprofessionalism = new JLabel("Professionalism:",JLabel.CENTER);
m_labelprofessionalism.setBackground(Color.blue);
m_labelprofessionalism.setForeground(Color.white);
m_labeljump = new JLabel("Jump:",JLabel.CENTER);
m_labeljump.setBackground(Color.blue);
m_labeljump.setForeground(Color.white);
m_labelstamina = new JLabel("Stamina:",JLabel.CENTER);
m_labelstamina.setBackground(Color.blue);
m_labelstamina.setForeground(Color.white);
m_labelbravery = new JLabel("Bravery:",JLabel.CENTER);
m_labelbravery.setBackground(Color.blue);
m_labelbravery.setForeground(Color.white);
m_labelfitness = new JLabel("Fitness:",JLabel.CENTER);
m_labelfitness.setBackground(Color.blue);
m_labelfitness.setForeground(Color.white);
m_labelexperience = new JLabel("Experience",JLabel.CENTER);
m_labelexperience.setBackground(Color.blue);
m_labelexperience.setForeground(Color.white);
//creation of textfields to hold the data
//making them non-editable and b/ground of black with white text
m_name = new JTextField(20);
m_name.setEditable(false);
m_name.setBackground(Color.black);
m_name.setForeground(Color.white);
m_age = new JTextField(2);
m_age.setEditable(false);
m_age.setBackground(Color.black);
m_age.setForeground(Color.white);
m_weight = new JTextField(3);
m_weight.setEditable(false);
m_weight.setBackground(Color.black);
m_weight.setForeground(Color.white);
m_speed = new JTextField(2);
m_speed.setEditable(false);
m_speed.setBackground(Color.black);
m_speed.setForeground(Color.white);
m_acceleration = new JTextField(2);
m_acceleration.setEditable(false);
m_acceleration.setBackground(Color.black);
m_acceleration.setForeground(Color.white);
m_professionalism = new JTextField(2);
m_professionalism.setEditable(false);
m_professionalism.setBackground(Color.black);
m_professionalism.setForeground(Color.white);
m_jump = new JTextField(2);
m_jump.setEditable(false);
m_jump.setBackground(Color.black);
m_jump.setForeground(Color.white);
m_stamina = new JTextField(2);
m_stamina.setEditable(false);
m_stamina.setBackground(Color.black);
m_stamina.setForeground(Color.white);
m_bravery = new JTextField(2);
m_bravery.setEditable(false);
m_bravery.setBackground(Color.black);
m_bravery.setForeground(Color.white);
m_fitness = new JTextField(2);
m_fitness.setEditable(false);
m_fitness.setBackground(Color.black);
m_fitness.setForeground(Color.white);
m_experience = new JTextField(2);
m_experience.setEditable(false);
m_experience.setBackground(Color.black);
m_experience.setForeground(Color.white);
//create a panel to hold this data
Panel data = new Panel();
data.setLayout(new GridLayout(0,4));
data.setBackground(Color.blue);
data.add(m_labelname);
data.add(m_name);
data.add(m_labelage);
data.add(m_age);
data.add(m_labelweight);
data.add(m_weight);
data.add(m_labelspeed);
data.add(m_speed);
data.add(m_labelacceleration);
data.add(m_acceleration);
data.add(m_labelprofessionalism);
data.add(m_professionalism);
data.add(m_labeljump);
data.add(m_jump);
data.add(m_labelstamina);
data.add(m_stamina);
data.add(m_labelbravery);
data.add(m_bravery);
data.add(m_labelfitness);
data.add(m_fitness);
data.add(m_labelexperience);
data.add(m_experience);
getContentPane().add(data, BorderLayout.CENTER);
public void buildDefaultGUI() //construct the default components for GUI
JToolBar wndToolBar = new JToolBar();
wndToolBar.setBackground(Color.green);
wndToolBar.setFloatable(false);
m_buttonFirst = new JButton( new ImageIcon( "graphic/myFirst.gif" ) );
m_buttonPrevious = new JButton(new ImageIcon( "graphic/myPrevious.gif" ) );
m_buttonNext = new JButton(new ImageIcon( "graphic/myNext.gif" ) );
m_buttonLast = new JButton(new ImageIcon( "graphic/myLast.gif" ) );
m_buttonClose = new JButton(new ImageIcon( "graphic/myClose.gif" ) );
m_mainbuttonClose = new JButton("CLOSE");
// implement action listener
m_buttonFirst.addActionListener(this);
m_buttonPrevious.addActionListener(this);
m_buttonNext.addActionListener(this);
m_buttonLast.addActionListener(this);
m_buttonClose.addActionListener(this);
m_mainbuttonClose.addActionListener(this);
//set the tool tips for each of the button
m_buttonFirst.setToolTipText( "Display first record" );
m_buttonPrevious.setToolTipText( "Display previous record" );
m_buttonNext.setToolTipText( "Display next record" );
m_buttonLast.setToolTipText( "Display last record" );
m_buttonClose.setToolTipText( "Close this window and return to game" );
m_mainbuttonClose.setToolTipText( "Close this window and return to game" );
m_mainbuttonClose.setBackground(Color.green);
//add these buttons to the toolbar
wndToolBar.add( m_buttonFirst );
wndToolBar.add( m_buttonPrevious );
wndToolBar.add( m_buttonNext );
wndToolBar.add( m_buttonLast );
wndToolBar.addSeparator(); //separator in the toolbar
wndToolBar.add( m_buttonClose );
getContentPane().add(wndToolBar, BorderLayout.NORTH);
getContentPane().add(m_mainbuttonClose, BorderLayout.SOUTH);
public void buildCourseGUI() //construct the course GUI
buildDefaultGUI();
public void buildJockeyGUI() //construct the jockey GUI
buildDefaultGUI();
public void actionPerformed( ActionEvent evt)
//button first record is pressed
if( evt.getSource() == m_buttonFirst )
try
if( m_DatabaseMan.m_resultSet.first() )
transferData(type1);
catch (SQLException exSQL )
System.err.println( exSQL.toString() );
//button next record is pressed
if( evt.getSource() == m_buttonNext )
try
if(!m_DatabaseMan.m_resultSet.isLast())
if(m_DatabaseMan.m_resultSet.next())
transferData(type1);
catch (SQLException exSQL )
System.err.println( exSQL.toString() );
//previous button is pressed
if( evt.getSource() == m_buttonPrevious )
try
if( !m_DatabaseMan.m_resultSet.first())
if(m_DatabaseMan.m_resultSet.previous())
transferData(type1);
catch (SQLException exSQL )
System.err.println( exSQL.toString() );
//last button is pressed
if( evt.getSource() == m_buttonLast )
try
if(m_DatabaseMan.m_resultSet.last())
transferData(type1);
catch (SQLException exSQL )
System.err.println( exSQL.toString() );
// close button(s) pressed
if( evt.getSource() == m_buttonClose)
setVisible( false );
dispose(); //return the dialog window resources
m_DatabaseMan.CloseConnection();
if( evt.getSource() == m_mainbuttonClose)
setVisible( false );
dispose(); //return the dialog window resources
m_DatabaseMan.CloseConnection();
public void transferData(String type1) throws SQLException //return a String
if(type1 =="Horse")
//transfer horse details
m_name.setText(m_DatabaseMan.m_resultSet.getString("NAME"));
m_professionalism.setText(m_DatabaseMan.m_resultSet.getString("PROFESSIONALISM"));
m_speed.setText(m_DatabaseMan.m_resultSet.getString("SPEED"));
m_stamina.setText(m_DatabaseMan.m_resultSet.getString("STAMINA"));
m_weight.setText(m_DatabaseMan.m_resultSet.getString("WEIGHT"));
m_experience.setText(m_DatabaseMan.m_resultSet.getString("EXPERIENCE"));
m_fitness.setText(m_DatabaseMan.m_resultSet.getString("FITNESS"));
m_jump.setText(m_DatabaseMan.m_resultSet.getString("JUMP"));
m_age.setText(m_DatabaseMan.m_resultSet.getString("AGE"));
m_bravery.setText(m_DatabaseMan.m_resultSet.getString("BRAVERY"));
m_acceleration.setText(m_DatabaseMan.m_resultSet.getString("ACCELERATION"));
if(type1 =="Jockey")
m_name.setText(m_DatabaseMan.m_resultSet.getString("NAME"));
m_age.setText(m_DatabaseMan.m_resultSet.getString("AGE"));
if(type1 =="Course")
//transfer course details not implemented yet
} //end of class DBviewer
I ve set up an odbc driver and the database has data in it but I still get this run time error an no data is transfered to the dialog box
java.lang.StringIndexOutOfBoundsException: String index out of range: -1
at java.lang.String.substring(String.java:1525)
at sun.jdbc.odbc.JdbcOdbcResultSet.reWordAsCountQuery(JdbcOdbcResultSet.java:6268)
at sun.jdbc.odbc.JdbcOdbcResultSet.calculateRowCount(JdbcOdbcResultSet.java:6061)
at sun.jdbc.odbc.JdbcOdbcResultSet.initialize(JdbcOdbcResultSet.java:150)
at sun.jdbc.odbc.JdbcOdbcStatement.getResultSet(JdbcOdbcStatement.java:420)
at sun.jdbc.odbc.JdbcOdbcStatement.executeQuery(JdbcOdbcStatement.java:250)
at DatabaseMan.<init>(DatabaseMan.java:34)
at DBviewer.<init>(DBviewer.java:83)
at MainWindow.actionPerformed(MainWindow.java:266)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1450)
at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1504)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:378)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:250)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:216)
at java.awt.Component.processMouseEvent(Component.java:3715)
at java.awt.Component.processEvent(Component.java:3544)
at java.awt.Container.processEvent(Container.java:1164)
at java.awt.Component.dispatchEventImpl(Component.java:2593)
at java.awt.Container.dispatchEventImpl(Container.java:1213)
at java.awt.Component.dispatchEvent(Component.java:2497)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:2451)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:2216)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:2125)
at java.awt.Container.dispatchEventImpl(Container.java:1200)
at java.awt.Window.dispatchEventImpl(Window.java:914)
at java.awt.Component.dispatchEvent(Component.java:2497)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:339)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:131)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:98)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:85)
Im really stuck!!! any suggestions? thanks in advanceThank you for your response and sorry for the length
of code,
Thats was my first idea that it was asking for
or something I dont have but I checked my database and
I dont have any unusually large data entries (most
between 8-15 letters, the others are numbers) could it
be something wrong with how I've entered the database
in MsAccess, or am i barking up the wrong tree again!
Many thanks
RobI think you've misunderstood me. This has nothing to do with unusually large data entries, but rather the opposite. You are wrongly expecting data that is shorter than you think. When you call rs.getString(i) to retrieve a column value of a field, and you only want the first 5 characters in the column (instead of 10 or whatever the column size is), you would do something similar to the following:
String column_value = rs.getString(1).subtstring(0,5);The above expects a String that is at least 5 characters. Your problem is when your column value returned is less than the specified substring index ( in this case 5 ) it will throw an exception. If you changed your code to this, the error will not occur:
String column_value = rs.getString( 1 ).subtstring( 0, 5);
if ( column_value.length() > 5 )
column_value = column_value.substring( 0, 5 );
}Jamie -
Tomcat JDBC Realm Database Connection Error
Hello all,
I am trying to edit the server.xml file on Tomcat so I can use the JDBC Realm instead of the MemoryRealm. Hence, I will be able to read users, passwords and roles from a relational database instead of from the tomcat-users.xml.
I have tried following all the guides on the net I can find, my server.xml looks as follows (after making changes to allow it to use JDBC realm). The only problem is, when I try to run the application the server outputs the following: (after all of these errors have been kicked up a pop-up box then appears titled "Tomcat Manager Application", it asks for a User Name and Password. I have tried the standard user name of "ide" and the password next to it in tomcat-users.xml but it won't accept it. (I am using the netbeans IDE)).
Please could someone suggest any ideas of how I can get the server.xml to work with JDBC realm?
Using CATALINA_BASE: C:\Documents and Settings\Administrator\.netbeans\5.0beta\jakarta-tomcat-5.5.7_base
Using CATALINA_HOME: C:\Program Files\netbeans-5.0beta\enterprise2\jakarta-tomcat-5.5.7
Using CATALINA_TMPDIR: C:\Documents and Settings\Administrator\.netbeans\5.0beta\jakarta-tomcat-5.5.7_base\temp
Using JAVA_HOME: C:\j2sdk1.4.2_08
Created MBeanServer with ID: 1f934ad:107444b1d2b:-8000:ravinder-rdnzoa:1
31-Oct-2005 01:29:33 org.apache.coyote.http11.Http11Protocol init
INFO: Initializing Coyote HTTP/1.1 on http-8084
31-Oct-2005 01:29:34 org.apache.coyote.http11.Http11Protocol init
INFO: Initializing Coyote HTTP/1.1 on http-8443
31-Oct-2005 01:29:34 org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 2174 ms
31-Oct-2005 01:29:34 org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
31-Oct-2005 01:29:34 org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/5.5.7
31-Oct-2005 01:29:34 org.apache.catalina.realm.JDBCRealm start
SEVERE: Exception opening database connection
java.sql.SQLException: org.gjt.mm.mysql.Driver
at org.apache.catalina.realm.JDBCRealm.open(JDBCRealm.java:646)
at org.apache.catalina.realm.JDBCRealm.start(JDBCRealm.java:720)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1003)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:440)
at org.apache.catalina.core.StandardService.start(StandardService.java:450)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:683)
at org.apache.catalina.startup.Catalina.start(Catalina.java:537)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:271)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:409)
31-Oct-2005 01:29:34 org.apache.catalina.core.StandardHost start
INFO: XML validation disabled
31-Oct-2005 01:29:36 org.apache.catalina.startup.ContextConfig validateSecurityRoles
INFO: WARNING: Security role name IBM used in an <auth-constraint> without being defined in a <security-role>
31-Oct-2005 01:29:36 org.apache.catalina.startup.ContextConfig validateSecurityRoles
INFO: WARNING: Security role name Auditor used in an <auth-constraint> without being defined in a <security-role>
31-Oct-2005 01:29:37 org.apache.struts.tiles.TilesPlugin initDefinitionsFactory
INFO: Tiles definition factory loaded for module ''.
31-Oct-2005 01:29:37 org.apache.struts.validator.ValidatorPlugIn initResources
INFO: Loading validation rules file from '/WEB-INF/validator-rules.xml'
31-Oct-2005 01:29:37 org.apache.struts.validator.ValidatorPlugIn initResources
INFO: Loading validation rules file from '/WEB-INF/validation.xml'
31-Oct-2005 01:29:38 org.apache.catalina.startup.ContextConfig validateSecurityRoles
INFO: WARNING: Security role name IBM used in an <auth-constraint> without being defined in a <security-role>
31-Oct-2005 01:29:38 org.apache.struts.tiles.TilesPlugin initDefinitionsFactory
INFO: Tiles definition factory loaded for module ''.
31-Oct-2005 01:29:38 org.apache.struts.validator.ValidatorPlugIn initResources
INFO: Loading validation rules file from '/WEB-INF/validator-rules.xml'
31-Oct-2005 01:29:38 org.apache.struts.validator.ValidatorPlugIn initResources
INFO: Loading validation rules file from '/WEB-INF/validation.xml'
31-Oct-2005 01:29:39 org.apache.coyote.http11.Http11Protocol start
INFO: Starting Coyote HTTP/1.1 on http-8084
31-Oct-2005 01:29:39 org.apache.coyote.http11.Http11Protocol start
INFO: Starting Coyote HTTP/1.1 on http-8443
31-Oct-2005 01:29:40 org.apache.jk.common.ChannelSocket init
INFO: JK2: ajp13 listening on /0.0.0.0:8009
31-Oct-2005 01:29:40 org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/60 config=null
31-Oct-2005 01:29:40 org.apache.catalina.storeconfig.StoreLoader load
INFO: Find registry server-registry.xml at classpath resource
31-Oct-2005 01:29:40 org.apache.catalina.startup.Catalina start
INFO: Server startup in 5738 ms
31-Oct-2005 01:29:40 org.apache.catalina.realm.JDBCRealm authenticate
SEVERE: Exception performing authentication
java.sql.SQLException: org.gjt.mm.mysql.Driver
at org.apache.catalina.realm.JDBCRealm.open(JDBCRealm.java:646)
at org.apache.catalina.realm.JDBCRealm.authenticate(JDBCRealm.java:344)
at org.apache.catalina.authenticator.BasicAuthenticator.authenticate(BasicAuthenticator.java:181)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:446)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:825)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:738)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:526)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Thread.java:534)
31-Oct-2005 01:29:40 org.apache.catalina.realm.JDBCRealm authenticate
SEVERE: Exception performing authentication
java.sql.SQLException: org.gjt.mm.mysql.Driver
at org.apache.catalina.realm.JDBCRealm.open(JDBCRealm.java:646)
at org.apache.catalina.realm.JDBCRealm.authenticate(JDBCRealm.java:344)
at org.apache.catalina.authenticator.BasicAuthenticator.authenticate(BasicAuthenticator.java:181)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:446)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:825)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:738)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:526)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Thread.java:534)The server.xml looks as follows:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Example Server Configuration File -->
<!-- Note that component elements are nested corresponding to their
parent-child relationships with each other -->
<!-- A "Server" is a singleton element that represents the entire JVM,
which may contain one or more "Service" instances. The Server
listens for a shutdown command on the indicated port.
Note: A "Server" is not itself a "Container", so you may not
define subcomponents such as "Valves" or "Loggers" at this level.
-->
<Server port="8025" shutdown="SHUTDOWN">
<!-- Comment these entries out to disable JMX MBeans support used for the
administration web application -->
<Listener className="org.apache.catalina.mbeans.ServerLifecycleListener"/>
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/>
<Listener className="org.apache.catalina.storeconfig.StoreConfigLifecycleListener"/>
<!-- Global JNDI resources -->
<GlobalNamingResources>
<!-- Test entry for demonstration purposes -->
<Environment name="simpleValue" type="java.lang.Integer" value="30"/>
<!-- Editable user database that can also be used by
UserDatabaseRealm to authenticate users -->
<!-- RAV
<Resource name="UserDatabase" auth="Container" type="org.apache.catalina.UserDatabase" description="User database that can be updated and saved" factory="org.apache.catalina.users.MemoryUserDatabaseFactory" pathname="conf/tomcat-users.xml"/>
-->
</GlobalNamingResources>
<!-- A "Service" is a collection of one or more "Connectors" that share
a single "Container" (and therefore the web applications visible
within that Container). Normally, that Container is an "Engine",
but this is not required.
Note: A "Service" is not itself a "Container", so you may not
define subcomponents such as "Valves" or "Loggers" at this level.
-->
<!-- Define the Tomcat Stand-Alone Service -->
<Service name="Catalina">
<!-- A "Connector" represents an endpoint by which requests are received
and responses are returned. Each Connector passes requests on to the
associated "Container" (normally an Engine) for processing.
By default, a non-SSL HTTP/1.1 Connector is established on port 8080.
You can also enable an SSL HTTP/1.1 Connector on port 8443 by
following the instructions below and uncommenting the second Connector
entry. SSL support requires the following steps (see the SSL Config
HOWTO in the Tomcat 5 documentation bundle for more detailed
instructions):
* If your JDK version 1.3 or prior, download and install JSSE 1.0.2 or
later, and put the JAR files into "$JAVA_HOME/jre/lib/ext".
* Execute:
%JAVA_HOME%\bin\keytool -genkey -alias tomcat -keyalg RSA (Windows)
$JAVA_HOME/bin/keytool -genkey -alias tomcat -keyalg RSA (Unix)
with a password value of "changeit" for both the certificate and
the keystore itself.
By default, DNS lookups are enabled when a web application calls
request.getRemoteHost(). This can have an adverse impact on
performance, so you can disable it by setting the
"enableLookups" attribute to "false". When DNS lookups are disabled,
request.getRemoteHost() will return the String version of the
IP address of the remote client.
-->
<!-- Define a non-SSL HTTP/1.1 Connector on port 8080 -->
<Connector port="8084" maxThreads="150" minSpareThreads="25" maxSpareThreads="75" enableLookups="false" redirectPort="8443" acceptCount="100" connectionTimeout="20000" disableUploadTimeout="true" URIEncoding="utf-8"/>
<!-- Note : To disable connection timeouts, set connectionTimeout value
to 0 -->
<!-- Note : To use gzip compression you could set the following properties :
compression="on"
compressionMinSize="2048"
noCompressionUserAgents="gozilla, traviata"
compressableMimeType="text/html,text/xml"
-->
<!-- Define a SSL HTTP/1.1 Connector on port 8443 -->
<Connector port="8443"
maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" disableUploadTimeout="true"
acceptCount="100" scheme="https" secure="true"
clientAuth="false" sslProtocol="TLS" />
<!-- Define an AJP 1.3 Connector on port 8009 -->
<Connector port="8009" enableLookups="false" redirectPort="8443" protocol="AJP/1.3"/>
<!-- Define a Proxied HTTP/1.1 Connector on port 8082 -->
<!-- See proxy documentation for more information about using this. -->
<!--
<Connector port="8082"
maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" acceptCount="100" connectionTimeout="20000"
proxyPort="80" disableUploadTimeout="true" />
-->
<!-- An Engine represents the entry point (within Catalina) that processes
every request. The Engine implementation for Tomcat stand alone
analyzes the HTTP headers included with the request, and passes them
on to the appropriate Host (virtual host). -->
<!-- You should set jvmRoute to support load-balancing via AJP ie :
<Engine name="Standalone" defaultHost="localhost" jvmRoute="jvm1">
-->
<!-- Define the top level container in our container hierarchy -->
<Engine name="Catalina" defaultHost="localhost">
<!-- The request dumper valve dumps useful debugging information about
the request headers and cookies that were received, and the response
headers and cookies that were sent, for all requests received by
this instance of Tomcat. If you care only about requests to a
particular virtual host, or a particular application, nest this
element inside the corresponding <Host> or <Context> entry instead.
For a similar mechanism that is portable to all Servlet 2.4
containers, check out the "RequestDumperFilter" Filter in the
example application (the source for this filter may be found in
"$CATALINA_HOME/webapps/examples/WEB-INF/classes/filters").
Request dumping is disabled by default. Uncomment the following
element to enable it. -->
<!--
<Valve className="org.apache.catalina.valves.RequestDumperValve"/>
-->
<!-- Because this Realm is here, an instance will be shared globally -->
<!-- This Realm uses the UserDatabase configured in the global JNDI
resources under the key "UserDatabase". Any edits
that are performed against this UserDatabase are immediately
available for use by the Realm. -->
<!-- RAV
<Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/>
-->
<!-- Comment out the old realm but leave here for now in case we
need to go back quickly -->
<!--
<Realm className="org.apache.catalina.realm.MemoryRealm" />
-->
<!-- Replace the above Realm with one of the following to get a Realm
stored in a database and accessed via JDBC -->
<Realm className="org.apache.catalina.realm.JDBCRealm"
driverName="org.gjt.mm.mysql.Driver"
connectionURL="jdbc:mysql://localhost:3306/tomcatusers"
connectionName="root" connectionPassword="sikhism1"
userTable="users" userNameCol="user_name" userCredCol="user_pass"
userRoleTable="user_roles" roleNameCol="role_name" />
<!--
<Realm className="org.apache.catalina.realm.JDBCRealm"
driverName="oracle.jdbc.driver.OracleDriver"
connectionURL="jdbc:oracle:thin:@ntserver:1521:ORCL"
connectionName="scott" connectionPassword="tiger"
userTable="users" userNameCol="user_name" userCredCol="user_pass"
userRoleTable="user_roles" roleNameCol="role_name" />
-->
<!--
<Realm className="org.apache.catalina.realm.JDBCRealm"
driverName="sun.jdbc.odbc.JdbcOdbcDriver"
connectionURL="jdbc:odbc:CATALINA"
userTable="users" userNameCol="user_name" userCredCol="user_pass"
userRoleTable="user_roles" roleNameCol="role_name" />
-->
<!-- Define the default virtual host
Note: XML Schema validation will not work with Xerces 2.2.
-->
<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="false" xmlValidation="false" xmlNamespaceAware="false">
<!-- Defines a cluster for this node,
By defining this element, means that every manager will be changed.
So when running a cluster, only make sure that you have webapps in there
that need to be clustered and remove the other ones.
A cluster has the following parameters:
className = the fully qualified name of the cluster class
name = a descriptive name for your cluster, can be anything
mcastAddr = the multicast address, has to be the same for all the nodes
mcastPort = the multicast port, has to be the same for all the nodes
mcastBindAddr = bind the multicast socket to a specific address
mcastTTL = the multicast TTL if you want to limit your broadcast
mcastSoTimeout = the multicast readtimeout
mcastFrequency = the number of milliseconds in between sending a "I'm alive" heartbeat
mcastDropTime = the number a milliseconds before a node is considered "dead" if no heartbeat is received
tcpThreadCount = the number of threads to handle incoming replication requests, optimal would be the same amount of threads as nodes
tcpListenAddress = the listen address (bind address) for TCP cluster request on this host,
in case of multiple ethernet cards.
auto means that address becomes
InetAddress.getLocalHost().getHostAddress()
tcpListenPort = the tcp listen port
tcpSelectorTimeout = the timeout (ms) for the Selector.select() method in case the OS
has a wakup bug in java.nio. Set to 0 for no timeout
printToScreen = true means that managers will also print to std.out
expireSessionsOnShutdown = true means that
useDirtyFlag = true means that we only replicate a session after setAttribute,removeAttribute has been called.
false means to replicate the session after each request.
false means that replication would work for the following piece of code: (only for SimpleTcpReplicationManager)
<%
HashMap map = (HashMap)session.getAttribute("map");
map.put("key","value");
%>
replicationMode = can be either 'pooled', 'synchronous' or 'asynchronous'.
* Pooled means that the replication happens using several sockets in a synchronous way. Ie, the data gets replicated, then the request return. This is the same as the 'synchronous' setting except it uses a pool of sockets, hence it is multithreaded. This is the fastest and safest configuration. To use this, also increase the nr of tcp threads that you have dealing with replication.
* Synchronous means that the thread that executes the request, is also the
thread the replicates the data to the other nodes, and will not return until all
nodes have received the information.
* Asynchronous means that there is a specific 'sender' thread for each cluster node,
so the request thread will queue the replication request into a "smart" queue,
and then return to the client.
The "smart" queue is a queue where when a session is added to the queue, and the same session
already exists in the queue from a previous request, that session will be replaced
in the queue instead of replicating two requests. This almost never happens, unless there is a
large network delay.
-->
<!--
When configuring for clustering, you also add in a valve to catch all the requests
coming in, at the end of the request, the session may or may not be replicated.
A session is replicated if and only if all the conditions are met:
1. useDirtyFlag is true or setAttribute or removeAttribute has been called AND
2. a session exists (has been created)
3. the request is not trapped by the "filter" attribute
The filter attribute is to filter out requests that could not modify the session,
hence we don't replicate the session after the end of this request.
The filter is negative, ie, anything you put in the filter, you mean to filter out,
ie, no replication will be done on requests that match one of the filters.
The filter attribute is delimited by ;, so you can't escape out ; even if you wanted to.
filter=".*\.gif;.*\.js;" means that we will not replicate the session after requests with the URI
ending with .gif and .js are intercepted.
The deployer element can be used to deploy apps cluster wide.
Currently the deployment only deploys/undeploys to working members in the cluster
so no WARs are copied upons startup of a broken node.
The deployer watches a directory (watchDir) for WAR files when watchEnabled="true"
When a new war file is added the war gets deployed to the local instance,
and then deployed to the other instances in the cluster.
When a war file is deleted from the watchDir the war is undeployed locally
and cluster wide
-->
<!--
<Cluster className="org.apache.catalina.cluster.tcp.SimpleTcpCluster"
managerClassName="org.apache.catalina.cluster.session.DeltaManager"
expireSessionsOnShutdown="false"
useDirtyFlag="true"
notifyListenersOnReplication="true">
<Membership
className="org.apache.catalina.cluster.mcast.McastService"
mcastAddr="228.0.0.4"
mcastPort="45564"
mcastFrequency="500"
mcastDropTime="3000"/>
<Receiver
className="org.apache.catalina.cluster.tcp.ReplicationListener"
tcpListenAddress="auto"
tcpListenPort="4001"
tcpSelectorTimeout="100"
tcpThreadCount="6"/>
<Sender
className="org.apache.catalina.cluster.tcp.ReplicationTransmitter"
replicationMode="pooled"
ackTimeout="15000"/>
<Valve className="org.apache.catalina.cluster.tcp.ReplicationValve"
filter=".*\.gif;.*\.js;.*\.jpg;.*\.png;.*\.htm;.*\.html;.*\.css;.*\.txt;"/>
<Deployer className="org.apache.catalina.cluster.deploy.FarmWarDeployer"
tempDir="/tmp/war-temp/"
deployDir="/tmp/war-deploy/"
watchDir="/tmp/war-listen/"
watchEnabled="false"/>
</Cluster>
-->
<!-- Normally, users must authenticate themselves to each web app
individually. Uncomment the following entry if you would like
a user to be authenticated the first time they encounter a
resource protected by a security constraint, and then have that
user identity maintained across *all* web applications contained
in this virtual host. -->
<!--
<Valve className="org.apache.catalina.authenticator.SingleSignOn" />
-->
<!-- Access log processes all requests for this virtual host. By
default, log files are created in the "logs" directory relative to
$CATALINA_HOME. If you wish, you can specify a different
directory with the "directory" attribute. Specify either a relative
(to $CATALINA_HOME) or absolute path to the desired directory.
-->
<!--
<Valve className="org.apache.catalina.valves.AccessLogValve"
directory="logs" prefix="localhost_access_log." suffix=".txt"
pattern="common" resolveHosts="false"/>
-->
<!-- Access log processes all requests for this virtual host. By
default, log files are created in the "logs" directory relative to
$CATALINA_HOME. If you wish, you can specify a different
directory with the "directory" attribute. Specify either a relative
(to $CATALINA_HOME) or absolute path to the desired directory.
This access log implementation is optimized for maximum performance,
but is hardcoded to support only the "common" and "combined" patterns.
-->
<!--
<Valve className="org.apache.catalina.valves.FastCommonAccessLogValve"
directory="logs" prefix="localhost_access_log." suffix=".txt"
pattern="common" resolveHosts="false"/>
-->
<!-- Access log processes all requests for this virtual host. By
default, log files are created in the "logs" directory relative to
$CATALINA_HOME. If you wish, you can specify a different
directory with the "directory" attribute. Specify either a relative
(to $CATALINA_HOME) or absolute path to the desired directory.
This access log implementation is optimized for maximum performance,
but is hardcoded to support only the "common" and "combined" patterns.
This valve use NIO direct Byte Buffer to asynchornously store the
log.
-->
<!--
<Valve className="org.apache.catalina.valves.ByteBufferAccessLogValve"
directory="logs" prefix="localhost_access_log." suffix=".txt"
pattern="common" resolveHosts="false"/>
-->
</Host>
</Engine>
</Service>
</Server>Many thanks, and apologies for "dumping" all of the code here.So looking through the java api docs, I found that the tcUtilJDBCOperations has a connect string for the database. Below is the info it outlines. The questions I have it this. How do you specify the psdriver and URL along with do I need to do this as a persistent instance then add my selectstatement as a part of this or can I just specify this and the select statement will use this connection? Any help you can give would be appreciated.
tcUtilJDBCOperations
public tcUtilJDBCOperations(java.lang.String psDriver,
java.lang.String psUrl,
java.lang.String psUsername,
java.lang.String psPassword)Contructor that sets the parameters for connecting to a database
Parameters:
psDriver - The class name of the jdbc driver
psUrl - The URL of the database
psUsername - The username required to access the database
psPassword - The password for the above username
Nick -
J2EE and JDBC-ODBC bridge driver
Hi all,
in my application I want to access an ODBC database to get the data and put it into cloudscape. In my resources.properties I added the jdbc driver
jdbcDriver.1.name=sun.jdbc.odbc.JdbcOdbcDriverand also added a datasource
jdbcDataSource.5.name=jdbc/MyOdbc
jdbcDataSource.5.url=jdbc\:odbc\:odbc-nameAfter starting j2ee 1.3.1 the server reports following error:
Error in creating data source object: jdbc/MyOdbcWhat's going wrong? Thanks for your help.
-chrisadditional information:
The phenomenon happens only if I use J2SDK 1.4.0. Running the 1.3.1 the driver is loaded without any problems.
Is it a security issue or am I not allowed to use 1.4 because it's too new?
-chris -
Silly jdbc.odbc question
Hi,
I am trying to connect to a database with jdbc.odbc.
What do I put in my classpath? Do I have to download the jdbc.odbc driver?
I'm missing something stupid I know!
Thanks,
VBVB -
you dont need to download the jdbc-odbc driver, as it comes packaged with the sdk. i think its in $JAVA_HOME/jre/rt.jar and is automatically in your classpath. You should be able to do a:
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
to load the driver into memory. you can then use the java.sql.DriverManager to obtain your connection:
DriverManager.getConnection( dbConnString, dbUser, dbPass);
where your connect string looks something like:
"jdbc:odbc:<dsn>" (i.e. "jdbc:odbc:fooDB").
you'll need to create a system dsn on your windows machine, or follow whatever odbc configuration instructions if on a different os platform.
i hope this helps.. been a long time since ive used the odbc bridge. you should probably try and use a vendor supplied driver pure java driver. this gets rid of the need for client specific configuration steps.
. -
How to append records in MSAccess through Java using JDBC:ODBC
Hello,
I was able to retrieve records from MSAccess database through JAVA over the JDBC-ODBC bridge.
If I want to append records to a table (for eg. photo1 table containing photono., length, breadth, area as
columns) I could not able to do so through JAVA.
I am using JTable with the above fields. The user is displayed with the JTable and he has to enter
data inside the JTable and press a button titled "Append". Then the JAVA program should append
whatever the user has entered in the JTable as a single record inside the MSAccess database.
Can anyone help me please?hi i too am having similar problem. i am able to create a table in ms access through java but when i insert values i get a msg that it has inserted the values but when i check the table by opening ms-access there are no values in the table.
the insert statement i am using is
" insert into tk1 values(3,'tarun')"
further i tried using the methods commit, setAutoCommit etc with the connection object. -NO GO.
can you help me ? -
Cannot access remote FoxPro dbf file using jdbc-odbc and system DSN
Hi all,
I have a foxpro database sitting on remote server (netware server). the dbf folder is shared and I can access it using windows explore on my weblogic server (windows 2003). I created a system dsn for that. I can access the database from the a stand alone java program using
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection surgConn = DriverManager.getConnection("jdbc:odbc:FoxDB", " ", " ");
But when I use the same thing in my weblogic 8.1 application, I cannot access the database. I didn't config any data source in weblogic 8.1
Why?
When I try this on my own computer - windows 2000, weblogic 8.1 workshop. remote foxpro database dbf folder. it works.
Any idea?
Thanks very muchLaura Ren wrote:
Hi all,
I have a foxpro database sitting on remote server (netware server). the dbf folder is shared and I can access it using windows explore on my weblogic server (windows 2003). I created a system dsn for that. I can access the database from the a stand alone java program using
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection surgConn = DriverManager.getConnection("jdbc:odbc:FoxDB", " ", " ");
But when I use the same thing in my weblogic 8.1 application, I cannot access the database.What exception do you get? WebLogic is just like any other Java App. That code
should work OK (though I have a better way)... Be warned that the JDBC ODBC
bridge is specifically dangerous. It is not threadsafe.
Joe
I didn't config any data source in weblogic 8.1
Why?
When I try this on my own computer - windows 2000, weblogic 8.1 workshop. remote foxpro database dbf folder. it works.
Any idea?
Thanks very much
Maybe you are looking for
-
How can I transfer an iPhoto album from my computer to my camera?
-
I uninstall and reinstall again. It is the same. It is empty box. I would like to use brush in the libraries
-
Compre macbook pro después del 1 de octubre y no tengo el iwork gratis
compre macbook pro después del 1 de octubre descargue la beta de maverick y no veo alguna actualización de iwork gratis sera que solo a mi me pase esto o es que no se a actualizado el iwork ?
-
How to set title of jsp page from resource bundle
hi , How to set title of jsp page from resource bundle....
-
I got a StringTokenizer: while ((fullText = in.readLine()) != null) { ++line; StringTokenizer tokenizer = new StringTokenizer(fullText, "="); }It take my fullText string "key = value" into "key " and " value", I want to take out those white s